请解释Express.js的基本服务器设置代码

Please explain the basic server setup code of Express.js

在此代码段中:

Const express = require('express')

Const app = express();

 /*Typeof express = function
 Typeof app = function*/

 app.get()

我的问题是:如果 app 是一个函数,那么我们如何使用点运算符来调用 get 函数,如果我们正在创建函数 express 的对象,那么我们为什么不使用 new 关键字来创建一个对象。

其次,module.exports 以对象格式导出文字,然后为什么我们在这里得到 typeof express 函数。

如有不对的地方还请指正

在JavaScriptfunctions are objects中,所以这是有效的:

function x() { 
  console.log("this is x()");
}
x.y = function() { 
  console.log("this is x.y()");
}

x();
x.y();

Express 和其他 JavaScript 工具广泛使用此功能。

如果您习惯了函数只是函数而不是对象本身的其他语言,这会显得非常奇怪。