I am using Express 4 server for Node.js
There is a router baked into Express like so:
in app.js
var router =
The truth is express is an excellent framework. But I have seen so many questions about route handling that we all wasted time. And also even when done correctly, it is just a heap of code that actually wasted people's time writing it and even more in correct stupid errors.
Try Route Magic
You want to do just 2 lines of code and have the module read your directory and file structure to handle all the app.use routing invocations, like this:
const magic = require('express-routemagic')
magic.use(app, __dirname, '[your route directory]')
That's really it! Nothing else.
For those you want to handle manually, just don't use pass the directory to Magic.
app.use('/i/repeat/myself', require('./routes/i/repeat/myself'))
app.use('/i/repeat/myself/again', require('./routes//i/repeat/myself/again'))
app.use('/i/keep/repeating/myself', require('./routes/i/keep/repeating/myself'))