Let's say we are using express. Why are we using callbacks like this:
var port = process.env.PORT || 8080;
app.listen(port, function(){
console.log('Listenning: ' + port);
});
instead of this:
var port = process.env.PORT || 8080;
var onBegin = function() {
console.log('Listenning: ' + port);
}
app.listen(port, onBegin);
Is this a must? Or the second one can cause problems? I see that lots of people use inline callbacks but why don't they simply define all callbacks in another block or a file? If this is a must, where can i find all best practices? For example i have found the following link, but can you recommend something else maybe? Like musts, basics and etc.
The link i have found: https://www.codementor.io/mattgoldspink/nodejs-best-practices-du1086jja
EDIT:
Here is the another callback function as a variable i am using with parameters:
var onGET = function(req, res) {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('User connected: ' + ip);
res.send('OK: ' + req.query.id);
}
app.get('*', onGET);