I am new to Node.js and Express and tried to get through some of the lessons. I can get basic routing that works at one level deep (for example http://localhost/help), but it's hard for me to get it working at two levels (for example, http://localhost/help/test).
Here are the relevant lines in app.js:
var help = require('./routes/help');
// also tried this
//var help_test = require('./routes/help/test');
var app = express();
app.use('/help', help);
app.use('/help/test', help.test);
// also tried this
//app.use('/help/test', test);
//app.use('/help/test', help_test);
In the routes directory, I have two files: index.js and test.js.
The .js index consists of:
var express = require('express');
var router = express.Router();
router.get('/', function(req, res) {
res.send('help');
});
module.exports = router;
The test.js file consists of:
var express = require('express');
var router = express.Router();
router.get('/test', function(req, res) {
res.send('help test!');
});
module.exports = router;
Now I can not start the server because of the configuration in app.js, but any changes that I make to start it lead to 404 error when I try to click http://localhost/help/test
source
share