BUT from the image you can see the file is correctly linked to. Why is it this exact router works in my root index.js and yet when I moved it to router/index.js it now shows a 'no such file' even though I did adjust the file location address.I've attached the error, the file that's making the call and also folder structure. I hope someone can tell me the silly error I'm making. Hoping you all can help me over the hump.Also I've printed out the code below just in case you are on a mobile or tablet and want to try helping from there.Image to the whole screen for context: https://www.dropbox.com/s/gld8yi16f6n44bx/code-screenshot.png?dl=0More code below.console.log[nodemon] starting `node index.js` [nodemon] restarting due to changes... [nodemon] starting `node index.js` Error: ENOENT: no such file or directory, open '../data/addressBook.json' at Object.openSync (fs.js:457:3) at Object.readFileSync (fs.js:359:35) at /Users/rkondrat/Web/BVC/kt-starter/routes/index.js:8:30 at Layer.handle [as handle_request] (/Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/layer.js:95:5) at next (/Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/layer.js:95:5) at /Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/index.js:335:12) at next (/Users/rkondrat/Web/BVC/kt-starter/node_modules/express/lib/router/index.js:275:10) Route (/routes/index.js)router.get("/", (req, res, next) => { const addressBookJSON = fs.readFileSync("../data/addressBook.json") // fs.readFileSync("../data/addressBook.json") console.log("addressBookJSON", addressBookJSON) const displayData = JSON.parse(addressBookJSON); res.render("index", { title: "Home", displayData }); }); module.exports = router Index.js (aka server.js) at the root of my serverconst mainRoutes = require('./routes/index') app.use('/', mainRoutes)
Submitted May 10, 2020 at 06:21AM by misterhtmlcss
No comments:
Post a Comment