im trying to show the content of my JSON file in html using express what I have is this
const data = require("./data.json");
const express = require("express");
const morgan = require("morgan");
var pug = require("pug");
//import mongoose from "mongoose";
//import port from "./config/config";
//const rutas = require("./routes/index.js");
//const routes = require("./routes");
console.log(data);
const app = express();
var path = require("path");
app.use(morgan("dev"));
app.set("view engine", "pug");
app.set("views", "./src/views");
app.set("port", process.env.PORT || 3000);
// levantar servidor
app.use(express.json()); // for parsing application/json
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencodedapp.set("port", process.env.PORT || _port);
app.use(morgan("dev"));
var datos = [];
datos = JSON.stringify(data);
var newEventList = data.map((data) => ({
id: data.id,
nombre: data.nombre,
categoria: data.categoria,
chef: data.chef,
Ingredientes: data.ingredientes.nombre,
cantidad: data.ingredientes.cantidad,
preparacion: data.preparacion,
}));
app.get("/", function (req, res) {
res.render("index", { title: "Hey", message: "Hello there!", newEventList });
});
but I have no idea how to pass that to html , im trying to use pug , but im really new to that too
thanks a lot
question from:
https://stackoverflow.com/questions/65908440/showing-static-json-file-content-in-html-using-express 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…