Sunday 15 July 2018

Express error - cannot find module

Hi,I'm trying to get into node.js and Express, and have been following a book (Getting MEAN With Mongo, Express, Angular, and Node). I've got through to halfway through chapter 4, but when I swapped from the single default controller to the two new ones instructed by the book, I've started getting the following error every time I try and run it:PS C:\Users\james\node\loc8r> node . module.js:549 throw err; ^ Error: Cannot find module 'C:\Users\james\node\loc8r' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3 The files I've modified are:/loc8r/app_server/routes/index.jsvar express = require('express'); var router = express.Router(); var controllerLocations = require('../controllers/locations'); var controllerOthers = require('../controllers/others'); /* Locations category controller */ router.get('/', controllerLocations.homelist); router.get('/locations', controllerLocations.locationInfo); router.get('/locations/review/new', controllerLocations.addNew); /* Others category controller */ router.get('/about', controllerOthers.about); module.exports = router; /loc8r/app_server/controllers/locations.js/* GET homepage */ module.exports.homelist = function(req, res) { res.render('index', {title: 'Home'}); }; /* GET Location info */ module.exports.locationInfo = function(req, res) { res.render('index', {title: 'Location info'}); }; /* GET add review page */ module.exports.addNew = function(req, res) { res.render('index', {title: 'Add a review'}); }; /loc8r/app_server/controllers/others.js/* GET about page */ module.exports.about = function(req, res) { res.render('index', {'title': 'About Loc8r'}); }; I'm aware that this folder structure isn't how things are done by default but it's the way the book recommends it be done for neatness. It worked fine with the default route and with the default route split into a route and a controller, but not since. I'm sure it's an obvious mistake but I've searched and can't find any answer. VS Code doesn't highlight any formatting errors so I've given up hope it's something glaring for me to fix like that.Node is v8.11.3, NPM is v5.6.0, Express is v 4.6.13 according to npm listCould someone also advise how I'd go about following back through the error message to work out where I've gone wrong?Many thanks,James

Submitted July 16, 2018 at 12:13AM by jamesm_14

No comments:

Post a Comment