var express = require('express')
var app = express()
or
var express = require('express'), app = express()
But why not
var app = require('express')()
Another question, why are there no semicolons in the below example from express:
var express = require('express')
var app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
Do you mean var app = require('express')()?
I’ve been wondering on the same thing. But there are times when you want to use express.static() along with app too, so in this case I think it’s better to use an express variable.
I’ve never tried (intentionally) omitting semicolons in JS (I’m comfortable with semicolons at the end of each line, thanks Java and C#). Maybe I’ll try it for once
there are some rare cases where omitting semi colons would potentially bring bugs
For instance:
function foo1()
{
return {
bar: "hello"
};
}
vs.
function foo2()
{
return
{
bar: "hello"
};
}
Though both looks about the same, the first one will output {bar: Hello'},and the second would output undefined. JS will autmatically put semicolon after the return keyword in the second function, thus executing and exiting without going to {bar: 'hello}