index

Module exports.

index

index

Module exports.

index

index

Module exports.

index

index

Module exports.

index

index

Module exports.

index

index

Module exports.

index

Server

Re-usable server.

new Server(associatedApp: express, port: (string | number), opts: {name: string, useHttps: boolean, useHttp2: boolean, securityOptions: object, callback: function (Server), showPublicIP: boolean, silent: boolean, gracefulClose: boolean, autoRun: boolean})
Parameters
associatedApp (express) Associated express application
port ((string | number) = (process.env.PORT||3e3)) Port/pipe to use
opts ({name: string, useHttps: boolean, useHttp2: boolean, securityOptions: object, callback: function (Server), showPublicIP: boolean, silent: boolean, gracefulClose: boolean, autoRun: boolean} = {name:'Server',useHttps:false,securityOptions:{},callback:(server)=>{},showPublicIP:false,silent:false,gracefulClose:true,autoRun:false}) Options including the server's name, HTTPS, options needed for the HTTPs server (public keys and certificates), callback called within the listen event and whether it should show its public IP and whether it needs to be silent ( which won't affect the public IP log ) and if it should run automatically upon being instantiated.
Static Members
app
app
port
port
name
name
useHttps
useHttps
useHttp2
useHttp2
options
options
server
server
silent
silent
run()
onError(error)
close()
toString()

bodyParser

Create a middleware to parse json and urlencoded bodies.

bodyParser(options: object?): function
Deprecated: This is deprecated.
Parameters
options (object?)
Returns
function:

View

Initialize a new View with the given name.

Options:

  • defaultEngine the default template engine name
  • engines template engine require() cache
  • root root path for view lookup
new View(name: string, options: object)
Parameters
name (string)
options (object)

Route

Initialize Route with the given path,

new Route(path: String)
Parameters
path (String)

proto

Initialize a new Router with the given options.

proto
Parameters
options (Object?)
Returns
Router: which is an callable function
Static Members
param(name, fn)
use(fn)
route(path)

req

Request prototype.

req
Static Members
get
accepts(type)
acceptsEncodings()
acceptsCharsets()
acceptsLanguages()
range(size, options?)
param(name, defaultValue?)
is(types)

defineGetter

Return the protocol string "http" or "https" when requested with TLS. When the "trust proxy" setting trusts the socket address, the "X-Forwarded-Proto" header field will be trusted and used if present.

If you're running behind a reverse proxy that supplies https for you this may be enabled.

defineGetter
Returns
String:

defineGetter

Short-hand for:

req.protocol === 'https'

defineGetter
Returns
Boolean:

defineGetter

Return the remote address from the trusted proxy.

The is the remote address on the socket unless "trust proxy" is set.

defineGetter
Returns
String:

defineGetter

When "trust proxy" is set, trusted proxy addresses + client.

For example if the value were "client, proxy1, proxy2" you would receive the array ["client", "proxy1", "proxy2"] where "proxy2" is the furthest down-stream and "proxy1" and "proxy2" were trusted.

defineGetter
Returns
Array:

defineGetter

Return subdomains as an array.

Subdomains are the dot-separated parts of the host before the main domain of the app. By default, the domain of the app is assumed to be the last two parts of the host. This can be changed by setting "subdomain offset".

For example, if the domain is "tobi.ferrets.example.com": If "subdomain offset" is not set, req.subdomains is ["ferrets", "tobi"]. If "subdomain offset" is 3, req.subdomains is ["tobi"].

defineGetter
Returns
Array:

defineGetter

Short-hand for url.parse(req.url).pathname.

defineGetter
Returns
String:

defineGetter

Parse the "Host" header field to a hostname.

When the "trust proxy" setting trusts the socket address, the "X-Forwarded-Host" header field will be trusted.

defineGetter
Returns
String:

defineGetter

Check if the request is fresh, aka Last-Modified and/or the ETag still match.

defineGetter
Returns
Boolean:

defineGetter

Check if the request is stale, aka "Last-Modified" and / or the "ETag" for the resource has changed.

defineGetter
Returns
Boolean:

defineGetter

Check if the request was an XMLHttpRequest.

defineGetter
Returns
Boolean:

res

Response prototype.

res
Static Members
status(code)
send(body)
json(obj)
jsonp(obj)
sendStatus(statusCode)
sendFile(path, options, callback)
sendfile(path, options, callback)
download(path, filename, options, callback)
contentType
format(obj)
attachment(filename)
append(field, val)
set
get(field)
clearCookie(name, options?)
cookie(name, value, options?)
location(url)
redirect(url)
vary(field)
render(view, options, callback)

morgan

Create a logger middleware.

morgan(format: (String | Function), options: Object?): Function
Parameters
format ((String | Function))
options (Object?)
Returns
Function: middleware

format

Define a format with the given name.

format(name: string, fmt: (string | function))
Parameters
name (string)
fmt ((string | function))

token

Define a token function with the given name, and callback fn(req, res).

token(name: string, fn: function)
Parameters
name (string)
fn (function)

compile

Compile a format string into a function.

compile(format: string): function
Parameters
format (string)
Returns
function:

createBufferStream

Create a basic buffering stream.

createBufferStream(stream: object, interval: number)
Parameters
stream (object)
interval (number)

getFormatFunction

Lookup and compile a named format function.

getFormatFunction(name: string): function
Parameters
name (string)
Returns
function:

defineProperty

JSON parser.

defineProperty

defineProperty

Raw parser.

defineProperty

defineProperty

Text parser.

defineProperty

defineProperty

URL-encoded parser.

defineProperty

json

Create a middleware to parse JSON bodies.

json(options: object?): function
Parameters
options (object?)
Returns
function:

urlencoded

Create a middleware to parse urlencoded bodies.

urlencoded(options: object?): function
Parameters
options (object?)
Returns
function: