What is the use of var app = express(); in the process of creating a Node.Js Application?

后端 未结 2 1811
梦毁少年i
梦毁少年i 2021-02-04 14:46

I am new to the world of Node.js.I am trying to learn through an example.I have encountered the following statements in the \"app.js\" .

  var express = require(         


        
2条回答
  •  清歌不尽
    2021-02-04 15:34

    The real difference between require('express') and express() is that require('express') allows you to have access to any public functions or properties exposed by module.exports.

    The express() syntax is the equivalent of saying new express(). It creates a new instance of express that you can then assign to a variable and interact with.

    That is why the standard creation pattern for Express is

    // Import the Express module
    var express = require('express');
    
    // Create a new Express Instance
    var app = express();
    

提交回复
热议问题