eYe eYe - 1 year ago 53
Node.js Question

What does the empty parentheses mean after 'require' declaration in Node.js?


I see sometimes a declaration like this:

var App = require('express')();

What do the empty brackets
at the end mean?

I am suspecting the declaration above is equivalent to something like:

var Express = require('express');
var App = Express();

Is that right?


As James already answered the module returns a function which is than invoked in this manner.

Here a simple code sample to make it easier understandable.

function a() {
    function b() {
        alert('Alert me!');
    return b;
//alerts 'Alert me!'