js

why i am getting a "throw err" in this app.js file?

hello guys
pls consider this code and tell me why i am getting a "throw err"
app.js file
 
const express = require("express");
const app = express();
const jsonData = require("./jsonFile/data.json");

app.set("view engine", "ejs");

app.use(require("./routes/index"));
app.use(jsonData);

app.listen(3000, ()=>{
console.log("listening on port");
})

index.js file
const express = require("express");
const router = express.Router();
const jsonData = require("./jsonFile/data.json");

router.get("/index", (req, res)=>{
const retrieveData = jsonData.datafile;
res.render("index", {
retrieveData: retrieveData
});
});

module.exports = router;

finally the ejs file
<% retrieveData.forEach((data)=>{ %>

<h3><%= data.title %></h3>
<% }) %>
I am starting to develop a basic site yet i have ran into this err early in this project.
pls helpthanks
You already invited:

bobkik

Upvotes from:

start by rewinding in steps. Make sure you test each new line of code and that it is working the way you want. For example, testthat the server is able to run on its own. Next, check specifically what happens when you open the site wthout trying to read or send data yet. so on and so forth.

Adam Burnham

Upvotes from:

line 9 app.use(require("./routes/index")). What are you trying to do there? if you are trying to use express router then that line needs to be app.use("./routes/index", filename) and you need to import the router using object deconstructing

If you wanna answer this question please Login or Register