Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Implements

Index

Constructors

constructor

Properties

app

charset

charset: string

chunkedEncoding

chunkedEncoding: boolean

connection

connection: Socket

finished

finished: boolean

headersSent

headersSent: boolean

json

json: Send

Send JSON response.

Examples:

res.json(null);
res.json({ user: 'tj' });
res.status(500).json('oh noes!');
res.status(404).json('I dont have that');

jsonp

jsonp: Send

Send JSON response with JSONP callback support.

Examples:

res.jsonp(null);
res.jsonp({ user: 'tj' });
res.status(500).jsonp('oh noes!');
res.status(404).jsonp('I dont have that');

locals

locals: any

Optional req

req: Request

After middleware.init executed, Response will contain req property See: express/lib/middleware/init.js

send

send: Send

Send a response.

Examples:

res.send(new Buffer('wahoo'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
res.status(404).send('Sorry, cant find that');

sendDate

sendDate: boolean

shouldKeepAlive

shouldKeepAlive: boolean

statusCode

statusCode: number

statusMessage

statusMessage: string

upgrading

upgrading: boolean

useChunkedEncodingByDefault

useChunkedEncodingByDefault: boolean

writable

writable: boolean

writableFinished

writableFinished: boolean

writableHighWaterMark

writableHighWaterMark: number

writableLength

writableLength: number

Static defaultMaxListeners

defaultMaxListeners: number

Methods

_destroy

  • _destroy(error: Error | null, callback: function): void
  • Parameters

    • error: Error | null
    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

_final

  • _final(callback: function): void
  • Parameters

    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

_write

  • _write(chunk: any, encoding: string, callback: function): void
  • Parameters

    • chunk: any
    • encoding: string
    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

Optional _writev

  • _writev(chunks: Array<object>, callback: function): void
  • Parameters

    • chunks: Array<object>
    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

addListener

  • addListener(event: "close", listener: function): this
  • addListener(event: "drain", listener: function): this
  • addListener(event: "error", listener: function): this
  • addListener(event: "finish", listener: function): this
  • addListener(event: "pipe", listener: function): this
  • addListener(event: "unpipe", listener: function): this
  • addListener(event: string | symbol, listener: function): this
  • Event emitter The defined events on documents including:

    1. close
    2. drain
    3. error
    4. finish
    5. pipe
    6. unpipe

    Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "drain"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

  • Parameters

    • event: "finish"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "pipe"
    • listener: function

    Returns this

  • Parameters

    • event: "unpipe"
    • listener: function

    Returns this

  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

addTrailers

append

  • append(field: string, value?: string[] | string): Response
  • Appends the specified value to the HTTP response header field. If the header is not already set, it creates the header with the specified value. The value parameter can be a string or an array.

    Note: calling res.set() after res.append() will reset the previously-set header value.

    since

    4.11.0

    Parameters

    • field: string
    • Optional value: string[] | string

    Returns Response

assignSocket

  • assignSocket(socket: Socket): void

attachment

  • attachment(filename?: undefined | string): Response
  • Set Content-Disposition header to attachment with optional filename.

    Parameters

    • Optional filename: undefined | string

    Returns Response

clearCookie

  • clearCookie(name: string, options?: any): Response
  • Clear cookie name.

    Parameters

    • name: string
    • Optional options: any

    Returns Response

contentType

  • Set Content-Type response header with type through mime.lookup() when it does not contain "/", or set the Content-Type to type otherwise.

    Examples:

    res.type('.html');
    res.type('html');
    res.type('json');
    res.type('application/json');
    res.type('png');

    Parameters

    • type: string

    Returns Response

cookie

  • Set cookie name to val, with the given options.

    Options:

    • maxAge max-age in milliseconds, converted to expires
    • signed sign the cookie
    • path defaults to "/"

    Examples:

    // "Remember Me" for 15 minutes res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });

    // save as above res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })

    Parameters

    Returns Response

  • Parameters

    Returns Response

  • Parameters

    • name: string
    • val: any

    Returns Response

cork

  • cork(): void
  • Returns void

destroy

  • destroy(error?: Error): void
  • Parameters

    Returns void

detachSocket

  • detachSocket(socket: Socket): void

download

  • download(path: string, fn?: Errback): void
  • download(path: string, filename: string, fn?: Errback): void
  • download(path: string, filename: string, options: any, fn?: Errback): void
  • Transfer the file at the given path as an attachment.

    Optionally providing an alternate attachment filename, and optional callback fn(err). The callback is invoked when the data transfer is complete, or when an error has ocurred. Be sure to check res.headerSent if you plan to respond.

    The optional options argument passes through to the underlying res.sendFile() call, and takes the exact same parameters.

    This method uses res.sendfile().

    Parameters

    • path: string
    • Optional fn: Errback

    Returns void

  • Parameters

    • path: string
    • filename: string
    • Optional fn: Errback

    Returns void

  • Parameters

    • path: string
    • filename: string
    • options: any
    • Optional fn: Errback

    Returns void

emit

  • emit(event: "close"): boolean
  • emit(event: "drain"): boolean
  • emit(event: "error", err: Error): boolean
  • emit(event: "finish"): boolean
  • emit(event: "pipe", src: Readable): boolean
  • emit(event: "unpipe", src: Readable): boolean
  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: "close"

    Returns boolean

  • Parameters

    • event: "drain"

    Returns boolean

  • Parameters

    • event: "error"
    • err: Error

    Returns boolean

  • Parameters

    • event: "finish"

    Returns boolean

  • Parameters

    Returns boolean

  • Parameters

    Returns boolean

  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

end

  • end(cb?: undefined | function): void
  • end(chunk: any, cb?: undefined | function): void
  • end(chunk: any, encoding: string, cb?: undefined | function): void
  • Parameters

    • Optional cb: undefined | function

    Returns void

  • Parameters

    • chunk: any
    • Optional cb: undefined | function

    Returns void

  • Parameters

    • chunk: any
    • encoding: string
    • Optional cb: undefined | function

    Returns void

eventNames

  • eventNames(): Array<string | symbol>

flushHeaders

  • flushHeaders(): void

format

  • Respond to the Acceptable formats using an obj of mime-type callbacks.

    This method uses req.accepted, an array of acceptable types ordered by their quality values. When "Accept" is not present the first callback is invoked, otherwise the first match is used. When no match is performed the server responds with 406 "Not Acceptable".

    Content-Type is set for you, however if you choose you may alter this within the callback using res.type() or res.set('Content-Type', ...).

    res.format({ 'text/plain': function(){ res.send('hey'); },

     'text/html': function(){
       res.send('<p>hey</p>');
     },
    
     'appliation/json': function(){
       res.send({ message: 'hey' });
     }

    });

    In addition to canonicalized MIME types you may also use extnames mapped to these types:

    res.format({ text: function(){ res.send('hey'); },

     html: function(){
       res.send('<p>hey</p>');
     },
    
     json: function(){
       res.send({ message: 'hey' });
     }

    });

    By default Express passes an Error with a .status of 406 to next(err) if a match is not made. If you provide a .default callback it will be invoked instead.

    Parameters

    • obj: any

    Returns Response

get

  • get(field: string): string
  • Get value for header field.

    Parameters

    • field: string

    Returns string

getHeader

  • getHeader(name: string): number | string | string[] | undefined
  • Parameters

    • name: string

    Returns number | string | string[] | undefined

getHeaderNames

  • getHeaderNames(): string[]

getHeaders

getMaxListeners

  • getMaxListeners(): number

hasHeader

  • hasHeader(name: string): boolean
  • Parameters

    • name: string

    Returns boolean

header

  • header(field: any): Response
  • header(field: string, value?: undefined | string): Response
  • Parameters

    • field: any

    Returns Response

  • Parameters

    • field: string
    • Optional value: undefined | string

    Returns Response

links

listenerCount

  • listenerCount(type: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

location

  • Set the location header to url.

    The given url can also be the name of a mapped url, for example by default express supports "back" which redirects to the Referrer or Referer headers or "/".

    Examples:

    res.location('/foo/bar').; res.location('http://example.com'); res.location('../login'); // /blog/post/1 -> /blog/login

    Mounting:

    When an application is mounted and res.location() is given a path that does not lead with "/" it becomes relative to the mount-point. For example if the application is mounted at "/blog", the following would become "/blog/login".

     res.location('login');

    While the leading slash would result in a location of "/login":

     res.location('/login');

    Parameters

    • url: string

    Returns Response

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: "close", listener: function): this
  • on(event: "drain", listener: function): this
  • on(event: "error", listener: function): this
  • on(event: "finish", listener: function): this
  • on(event: "pipe", listener: function): this
  • on(event: "unpipe", listener: function): this
  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "drain"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

  • Parameters

    • event: "finish"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "pipe"
    • listener: function

    Returns this

  • Parameters

    • event: "unpipe"
    • listener: function

    Returns this

  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: "close", listener: function): this
  • once(event: "drain", listener: function): this
  • once(event: "error", listener: function): this
  • once(event: "finish", listener: function): this
  • once(event: "pipe", listener: function): this
  • once(event: "unpipe", listener: function): this
  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "drain"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

  • Parameters

    • event: "finish"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "pipe"
    • listener: function

    Returns this

  • Parameters

    • event: "unpipe"
    • listener: function

    Returns this

  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

pipe

  • pipe<T>(destination: T, options?: undefined | object): T
  • Type parameters

    Parameters

    • destination: T
    • Optional options: undefined | object

    Returns T

prependListener

  • prependListener(event: "close", listener: function): this
  • prependListener(event: "drain", listener: function): this
  • prependListener(event: "error", listener: function): this
  • prependListener(event: "finish", listener: function): this
  • prependListener(event: "pipe", listener: function): this
  • prependListener(event: "unpipe", listener: function): this
  • prependListener(event: string | symbol, listener: function): this

prependOnceListener

  • prependOnceListener(event: "close", listener: function): this
  • prependOnceListener(event: "drain", listener: function): this
  • prependOnceListener(event: "error", listener: function): this
  • prependOnceListener(event: "finish", listener: function): this
  • prependOnceListener(event: "pipe", listener: function): this
  • prependOnceListener(event: "unpipe", listener: function): this
  • prependOnceListener(event: string | symbol, listener: function): this

rawListeners

  • rawListeners(event: string | symbol): Function[]

redirect

  • redirect(url: string): void
  • redirect(status: number, url: string): void
  • redirect(url: string, status: number): void
  • Redirect to the given url with optional response status defaulting to 302.

    The resulting url is determined by res.location(), so it will play nicely with mounted apps, relative paths, "back" etc.

    Examples:

    res.redirect('/foo/bar'); res.redirect('http://example.com'); res.redirect(301, 'http://example.com'); res.redirect('http://example.com', 301); res.redirect('../login'); // /blog/post/1 -> /blog/login

    Parameters

    • url: string

    Returns void

  • Parameters

    • status: number
    • url: string

    Returns void

  • Parameters

    • url: string
    • status: number

    Returns void

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeHeader

  • removeHeader(name: string): void

removeListener

  • removeListener(event: "close", listener: function): this
  • removeListener(event: "drain", listener: function): this
  • removeListener(event: "error", listener: function): this
  • removeListener(event: "finish", listener: function): this
  • removeListener(event: "pipe", listener: function): this
  • removeListener(event: "unpipe", listener: function): this
  • removeListener(event: string | symbol, listener: function): this

render

  • render(view: string, options?: undefined | object, callback?: undefined | function): void
  • render(view: string, callback?: undefined | function): void
  • Render view with the given options and optional callback fn. When a callback function is given a response will not be made automatically, otherwise a response of 200 and text/html is given.

    Options:

    • cache boolean hinting to the engine it should cache
    • filename filename of the view being rendered

    Parameters

    • view: string
    • Optional options: undefined | object
    • Optional callback: undefined | function

    Returns void

  • Parameters

    • view: string
    • Optional callback: undefined | function

    Returns void

sendFile

  • sendFile(path: string, fn?: Errback): void
  • sendFile(path: string, options: any, fn?: Errback): void
  • Transfer the file at the given path.

    Automatically sets the Content-Type response header field. The callback fn(err) is invoked when the transfer is complete or when an error occurs. Be sure to check res.sentHeader if you wish to attempt responding, as the header and some data may have already been transferred.

    Options:

    • maxAge defaulting to 0 (can be string converted by ms)
    • root root directory for relative filenames
    • headers object of headers to serve with file
    • dotfiles serve dotfiles, defaulting to false; can be "allow" to send them

    Other options are passed along to send.

    Examples:

    The following example illustrates how res.sendFile() may be used as an alternative for the static() middleware for dynamic situations. The code backing res.sendFile() is actually the same code, so HTTP cache support etc is identical.

    app.get('/user/:uid/photos/:file', function(req, res){
      var uid = req.params.uid
        , file = req.params.file;
    
      req.user.mayViewFilesFrom(uid, function(yes){
        if (yes) {
          res.sendFile('/uploads/' + uid + '/' + file);
        } else {
          res.send(403, 'Sorry! you cant see that.');
        }
      });
    });
    api

    public

    Parameters

    • path: string
    • Optional fn: Errback

    Returns void

  • Parameters

    • path: string
    • options: any
    • Optional fn: Errback

    Returns void

sendStatus

  • Set the response HTTP status code to statusCode and send its string representation as the response body.

    link

    http://expressjs.com/4x/api.html#res.sendStatus

    Examples:

    res.sendStatus(200); // equivalent to res.status(200).send('OK') res.sendStatus(403); // equivalent to res.status(403).send('Forbidden') res.sendStatus(404); // equivalent to res.status(404).send('Not Found') res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')

    Parameters

    • code: number

    Returns Response

sendfile

  • sendfile(path: string): void
  • sendfile(path: string, options: any): void
  • sendfile(path: string, fn: Errback): void
  • sendfile(path: string, options: any, fn: Errback): void
  • deprecated

    Use sendFile instead.

    Parameters

    • path: string

    Returns void

  • deprecated

    Use sendFile instead.

    Parameters

    • path: string
    • options: any

    Returns void

  • deprecated

    Use sendFile instead.

    Parameters

    Returns void

  • deprecated

    Use sendFile instead.

    Parameters

    • path: string
    • options: any
    • fn: Errback

    Returns void

set

  • set(field: any): Response
  • set(field: string, value?: undefined | string): Response
  • set(field: string, value?: string[]): Response
  • Set header field to val, or pass an object of header fields.

    Examples:

    res.set('Foo', ['bar', 'baz']); res.set('Accept', 'application/json'); res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });

    Aliased as res.header().

    Parameters

    • field: any

    Returns Response

  • Parameters

    • field: string
    • Optional value: undefined | string

    Returns Response

  • Parameters

    • field: string
    • Optional value: string[]

    Returns Response

setDefaultEncoding

  • setDefaultEncoding(encoding: string): this
  • Parameters

    • encoding: string

    Returns this

setHeader

  • setHeader(name: string, value: number | string | string[]): void
  • Parameters

    • name: string
    • value: number | string | string[]

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this

setTimeout

  • setTimeout(msecs: number, callback?: undefined | function): this
  • Parameters

    • msecs: number
    • Optional callback: undefined | function

    Returns this

status

  • Set status code.

    Parameters

    • code: number

    Returns Response

type

  • Set Content-Type response header with type through mime.lookup() when it does not contain "/", or set the Content-Type to type otherwise.

    Examples:

    res.type('.html');
    res.type('html');
    res.type('json');
    res.type('application/json');
    res.type('png');

    Parameters

    • type: string

    Returns Response

uncork

  • uncork(): void
  • Returns void

vary

  • Adds the field to the Vary response header, if it is not there already. Examples:

    res.vary('User-Agent').render('docs');

    Parameters

    • field: string

    Returns Response

write

  • write(chunk: any, cb?: undefined | function): boolean
  • write(chunk: any, encoding: string, cb?: undefined | function): boolean
  • Parameters

    • chunk: any
    • Optional cb: undefined | function

    Returns boolean

  • Parameters

    • chunk: any
    • encoding: string
    • Optional cb: undefined | function

    Returns boolean

writeContinue

  • writeContinue(callback?: undefined | function): void
  • Parameters

    • Optional callback: undefined | function

    Returns void

writeHead

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    Returns number

Generated using TypeDoc