我是Node.js的新手,如果這太明顯,我很抱歉!需要什麼('express')()返回?
我明白'require'的基本功能是它讀取一個javascript文件,執行該文件,然後繼續返回exports對象。現在
var app = require('express')();
,我可以做的東西一樣app.set('view engine', 'html');
,app.get()
等?
那麼,app
究竟是什麼,它是如何適合Web應用程序的大圖?
我是Node.js的新手,如果這太明顯,我很抱歉!需要什麼('express')()返回?
我明白'require'的基本功能是它讀取一個javascript文件,執行該文件,然後繼續返回exports對象。現在
var app = require('express')();
,我可以做的東西一樣app.set('view engine', 'html');
,app.get()
等?
那麼,app
究竟是什麼,它是如何適合Web應用程序的大圖?
您需要Express模塊。它基本上是一個Express方法的對象。這些功能可通過app.<function name>
訪問,如app.set
。您可以使用console.log(app.set)
將set
函數看作字符串。
該代碼輸出快遞對象:
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: '/' }
應用程序是模塊提供的所有功能的對象。
如果您想了解更多信息,請
console.log(app);