require('express')() 返回什么?

What does require('express')() return?

我是 Node.js 的新手,如果这太明显了,我很抱歉!

我了解 'require' 的基本功能是读取 javascript 文件,执行文件,然后继续 return 导出对象。

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

现在,我可以做 app.set('view engine', 'html');app.get() 等事情了?

那么,app 到底是什么?它如何融入 Web 应用程序的大局?

app 是一个包含模块提供的所有功能的对象。
如果您想了解更多信息,请尝试

 console.log(app);

您需要 Express 模块。它基本上是一个带有 Express 方法的对象。可以使用 app.<function name> 访问这些函数,例如 app.set。您可以 console.log(app.set)set 函数视为字符串。

此代码输出 Express 对象:

var express = require('express')
var app = express()

console.log(app)

输出:

{ [Function]
  init: [Function],
  defaultConfiguration: [Function],
  lazyrouter: [Function],
  handle: [Function],
  use: [Function: use],
  route: [Function],
  engine: [Function],
  param: [Function],
  set: [Function],
  path: [Function],
  enabled: [Function],
  disabled: [Function],
  enable: [Function],
  disable: [Function],
  get: [Function],
  post: [Function],
  put: [Function],
  head: [Function],
  delete: [Function],
  options: [Function],
  trace: [Function],
  copy: [Function],
  lock: [Function],
  mkcol: [Function],
  move: [Function],
  purge: [Function],
  propfind: [Function],
  proppatch: [Function],
  unlock: [Function],
  report: [Function],
  mkactivity: [Function],
  checkout: [Function],
  merge: [Function],
  'm-search': [Function],
  notify: [Function],
  subscribe: [Function],
  unsubscribe: [Function],
  patch: [Function],
  search: [Function],
  connect: [Function],
  all: [Function],
  del: [Function],
  render: [Function],
  listen: [Function],
  setMaxListeners: [Function: setMaxListeners],
  emit: [Function: emit],
  addListener: [Function: addListener],
  on: [Function: addListener],
  once: [Function: once],
  removeListener: [Function: removeListener],
  removeAllListeners: [Function: removeAllListeners],
  listeners: [Function: listeners],
  request: { app: [Circular] },
  response: { app: [Circular] },
  cache: {},
  settings:
   { 'x-powered-by': true,
     etag: 'weak',
     'etag fn': [Function: wetag],
     env: 'development',
     'query parser': 'extended',
     'query parser fn': [Function],
     'subdomain offset': 2,
     'trust proxy': false,
     'trust proxy fn': [Function: trustNone],
     view: [Function: View],
     views: '<<<<<obfuscated>>>>>>>',
     'jsonp callback name': 'callback' },
  engines: {},
  _events: { mount: [Function] },
  locals:
   { settings:
      { 'x-powered-by': true,
        etag: 'weak',
        'etag fn': [Function: wetag],
        env: 'development',
        'query parser': 'extended',
        'query parser fn': [Function],
        'subdomain offset': 2,
        'trust proxy': false,
        'trust proxy fn': [Function: trustNone],
        view: [Function: View],
        views: '<<<<<obfuscated>>>>>>>',
        'jsonp callback name': 'callback' } },
  mountpath: '/' }