什么需要('表达')()返回?

时间:2015-01-04 10:27:52

标签: javascript node.js express

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

我了解'的基本功能需要'是它读取一个javascript文件,执行该文件,然后继续返回导出对象。

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

现在,我可以执行app.set('view engine', 'html');app.get()等内容吗?

那么,app究竟是什么呢?它如何适应Web应用程序的大局?

2 个答案:

答案 0 :(得分:1)

app是一个具有模块提供的所有功能的对象 如果您想要更多信息,请尝试

 console.log(app);

答案 1 :(得分:1)

您需要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: '/' }