Reputation: 177
I have a express.js performance question. I have my server.js
where all the routes are defined and the child routes are imported like so:
const ROUTE__FOO = require('./routes/foo')
const ROUTE__BAR = require('./routes/bar')
app.use('/api/foo', ROUTE__FOO)
app.use('/api/bar', ROUTE__BAR)
So my question is: Is it better / faster to first require the routes inside a variable and then assign this variable to the express.js app.use
function? Or can I also do this:
app.use('/api/foo', require('./routes/foo'))
app.use('/api/bar', require('./routes/bar'))
Would there be any problems? I tried to find out what's better, but I couldn't get anything out for this specific problem.
Upvotes: 0
Views: 23
Reputation: 9246
It doesn't make any difference. For readability it's probably better to put the require
s at the top of the file, but performance wise it is the same.
Upvotes: 1