-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New features in 3.x
Sebastian Beltran edited this page Jul 3, 2025
·
26 revisions
This content is OUTDATED/ARCHIVED. Please refer to the website for up-to-date information.
-
express.applicationprototype -
express.requestprototype -
express.responseprototype
-
app.head()support -
app.localsobject (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 proxysetting enables the use of "X-Forwarded-Proto" forreq.protocolandres.redirecturl construction -
json spacessetting enables the developer to decide ifres.json()responds with nicely formatted JSON or compact json (this value is passed toJSON.stringify()) -
json replacersetting is a callback which is passed toJSON.stringify()inres.json()allowing you to manipulate and filter the JSON response
-
req.paththe request pathname -
req.protocolreturns the protocol string "http" or "https" (supports X-Forwarded-Proto viatrust proxysetting) -
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.acceptedarray of parsed Accept values sorted by quality -
req.acceptsCharset(charset)added -
req.acceptedCharsetsarray of parsed Accept-Charset values sorted by quality -
req.acceptsLanguage(lang)added -
req.acceptedLanguagesarray of parsed Accept-Language values sorted by quality -
req.signedCookiesobject containing signed cookies -
req.staleto see if a request is stale (based on ETag/Last-Modified) -
req.freshto complementreq.stale -
req.ipsto return an array of X-Forwarded-For values when "trust proxy" is enabled -
req.ipreturn the upstream addr inreq.ipsorreq.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.localsobject (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