-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
New features in 3.x
visionmedia edited this page Aug 30, 2012
·
25 revisions
-
express.application
prototype -
express.request
prototype -
express.response
prototype
-
app.head()
support -
app.locals
object (app.locals.foo = 'bar'
) -
app.locals(obj)
(app.locals({ foo: 'bar', bar: 'baz'})
) -
app.render(name[, options], callback)
to render app-level views -
app.engine(ext, callback)
to map template engines
-
trust proxy
setting enables the use of "X-Forwarded-Proto" forreq.protocol
andres.redirect
url construction -
json spaces
setting enables the developer to decide ifres.json()
responds with nicely formatted JSON or compact json (this value is passed toJSON.stringify()
) -
json replacer
setting is a callback which is passed toJSON.stringify()
inres.json()
allowing you to manipulate and filter the JSON response
-
req.path
the request pathname -
req.protocol
returns the protocol string "http" or "https" (supports X-Forwarded-Proto viatrust proxy
setting) -
req.get(field)
gets a request header field value (req.get('Host')
) -
req.accepts(type)
improved -
req.accepts(types)
added, returns the most viable type -
req.accepted
array of parsed Accept values sorted by quality -
req.acceptsCharset(charset)
added -
req.acceptedCharsets
array of parsed Accept-Charset values sorted by quality -
req.acceptsLanguage(lang)
added -
req.acceptedLanguages
array of parsed Accept-Language values sorted by quality -
req.signedCookies
object containing signed cookies -
req.stale
to see if a request is stale (based on ETag/Last-Modified) -
req.fresh
to complementreq.stale
-
req.ips
to return an array of X-Forwarded-For values when "trust proxy" is enabled -
req.ip
return the upstream addr inreq.ips
orreq.connection.remoteAddress
-
req.range(size)
parses the Range header field
-
res.get(field)
gets a response header field value (res.get('Content-Length')
) -
res.set(field, value)
sets a response header field (res.set('Content-Length', n)
) -
res.set(obj)
set several field values -
res.type(path)
alias of previousres.contentType(path)
, allowsres.type('json')
,res.type('application/x-whatever')
-
res.format(obj)
to format responses based on qvalue-sorted Accept - JSON cookie support (
res.cookie('cart', { ids: [1,2,3] })
,req.cookies.cart.ids
) - signed cookie support (
res.cookie(name, value, { signed: true })
) -
res.format(obj)
for content-negotiation -
res.locals
object (res.locals.foo = 'bar'
) -
res.locals(obj)
(res.locals({ foo: 'bar', bar: 'baz')
) -
res.redirect()
X-Forwarded-Proto support -
res.redirect()
relative support (res.redirect('../new')
,res.redirect('./edit')
, etc) -
res.links(obj)
set the "Link" header field with the given links -
res.jsonp([status], obj)
was added for explicit JSONP support