I used Bitnami to install a MEAN Stack
I am trying to understand something. I see a lot of tutorials which will show you could like this
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World');
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
Now within the command line, if I run node bin/www as per what the Bitnami documentation states, I get the error
TypeError: app.set is not a function
Now a simple solution to this is to add the following to the end of that code
module.exports = app;
However, instead of doing node bin/www if I invoked the file directly e.g. node app.js, the code will work without the extra addition above.
So really I am wondering why this is the case? I see a lot of online tutorials which do not assign app to module.exports. What is the difference between the two?