0


What is the difference between require() and require()()?
I have a code:
Not working

var app = require('express'); 
    var http = require('http').Server(app); 

    app.get('/', (req, res) => {
        res.send('Hello World');
    });

Working

var app = require('express')(); 
var http = require('http').Server(app); 

app.get('/', (req, res) => {
    res.send('Hello World');
});

Why?

  • in a short form,`()()` is an [IIFE](http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html). – vikscool Sep 07 '18 at 09:10
  • This is a simple thing. because, require("express") -> just get express function const express = require("express") // just function..; // console.log(express) -> define function info. require("express")() === express(); // function call! const express = require("express") // function call! express() === require("express")() – seunggabi Sep 07 '18 at 09:13

0 Answers0