Any reason why I can't use shorthand:
var app = require('express')();
If you considered this statement from your script,
app.use(express.static(__dirname+'views'));
you are using static
method of express.In order to use this method,you must import express
first and store it in some variables like u did
var express = require('express');
From express#express.js
exports.static = require('serve-static');
static
defined at class level.
then instantiate it
like this
var app = express();
to get the access to object level(prototype) method and properties like
app#use
app#engine
etc.
From express#application //line no 78
EDIT :
but then why can't I use app.static if I did var app = require('express')();
As I said,.static
is the class level method and not the instance/object(prototype) level.
So,by var app = require('express')()
you will get express instance / object (prototype) which dont have app.static method.So,you can't use.
Read more javascript-class-method-vs-class-prototype-method