I have a problem when starting NodeJS, similar to this post this link but did not have more feedback from those who asked and the solution presented in the answer did not help me either.
The example is from a book, from Code House, and are simple examples with directory errors but that make me break my mind because I'm starting with Node and Express.
The entire example used the same name as the variables in the book.
Here is the error:
Error: Cannot find module './app/routes/home.js'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (E:\projects\contatooh\config\express.js:2:12)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
contactoh / config / express.js
var express = require('express');
var home = require('./app/routes/home')
module.exports = function() {
var app = express();
app.set('port', 3000);
app.use(express.static('./public'));
app.set('view engine', 'ejs');
app.set('views','./app/views');
home(app);
return app;
};
contactoh / app / routes / home.js
var controller = require('./app/controllers/home');
module.exports = function(app) {
app.get('/', controler.index);
app.get('/index', controler.index);
}
UPDATE:
contactoh / app / controllers / home.js
module.exports = function(){
var controller = {};
controller.index = function(req, res){
res.render('index'), {nome: 'Express'});
};
return controller;
}
Directory organization:
contatooh
app
controllers
home.js
models
routes
home.js
views
index.ejs
config
express.js
node_modules
...
public
server.js
package.json