Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • ResBody

Hierarchy

  • Response
    • Response

Implements

  • WritableStream

Index

Constructors

constructor

  • new Response(req: IncomingMessage): Response

Properties

app

app: Application

charset

charset: string

chunkedEncoding

chunkedEncoding: boolean

connection

connection: Socket
deprecate

Use socket instead.

destroyed

destroyed: boolean

Optional duration

duration: undefined | string

finished

finished: boolean
deprecated

Use writableEnded instead.

headersSent

headersSent: boolean

json

json: Send<ResBody, this>

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<ResBody, this>

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 log

log: Logger

Optional req

req: Request

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

send

send: Send<ResBody, this>

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

socket

socket: Socket

statusCode

statusCode: number

statusMessage

statusMessage: string

upgrading

upgrading: boolean

useChunkedEncodingByDefault

useChunkedEncodingByDefault: boolean

writable

writable: boolean

writableCorked

writableCorked: number

writableEnded

writableEnded: boolean

writableFinished

writableFinished: boolean

writableHighWaterMark

writableHighWaterMark: number

writableLength

writableLength: number

writableObjectMode

writableObjectMode: boolean

Methods

_destroy

  • _destroy(error: Error | null, callback: (error?: Error | null) => void): void

_final

  • _final(callback: (error?: Error | null) => void): void
  • Parameters

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

          • Optional error: Error | null

          Returns void

    Returns void

_write

  • _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void
  • Parameters

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

          • Optional error: Error | null

          Returns void

    Returns void

Optional _writev

  • _writev(chunks: Array<{ chunk: any; encoding: string }>, callback: (error?: Error | null) => void): void
  • Parameters

    • chunks: Array<{ chunk: any; encoding: string }>
    • callback: (error?: Error | null) => void
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

addListener

  • addListener(event: "close", listener: () => void): this
  • addListener(event: "drain", listener: () => void): this
  • addListener(event: "error", listener: (err: Error) => void): this
  • addListener(event: "finish", listener: () => void): this
  • addListener(event: "pipe", listener: (src: Readable) => void): this
  • addListener(event: "unpipe", listener: (src: Readable) => void): this
  • addListener(event: string | symbol, listener: (...args: any[]) => void): this

addTrailers

  • addTrailers(headers: OutgoingHttpHeaders | Array<[string, string]>): void

append

  • append(field: string, value?: string[] | string): this
  • 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 this

assignSocket

  • assignSocket(socket: Socket): void

attachment

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

    Parameters

    • Optional filename: undefined | string

    Returns this

clearCookie

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

    Parameters

    • name: string
    • Optional options: any

    Returns this

contentType

  • contentType(type: string): this
  • 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 this

cookie

  • cookie(name: string, val: string, options: CookieOptions): this
  • cookie(name: string, val: any, options: CookieOptions): this
  • cookie(name: string, val: any): this
  • 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

    • name: string
    • val: string
    • options: CookieOptions

    Returns this

  • Parameters

    • name: string
    • val: any
    • options: CookieOptions

    Returns this

  • Parameters

    • name: string
    • val: any

    Returns this

cork

  • cork(): void

destroy

  • destroy(error?: Error): 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

end

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

    • Optional cb: undefined | (() => void)

    Returns void

  • Parameters

    • chunk: any
    • Optional cb: undefined | (() => void)

    Returns void

  • Parameters

    • chunk: any
    • encoding: string
    • Optional cb: undefined | (() => void)

    Returns void

eventNames

  • eventNames(): Array<string | symbol>

flushHeaders

  • flushHeaders(): void

format

  • format(obj: any): this
  • 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 this

get

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

    Parameters

    • field: string

    Returns string

getHeader

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

getHeaderNames

  • getHeaderNames(): string[]

getHeaders

  • getHeaders(): OutgoingHttpHeaders

getMaxListeners

  • getMaxListeners(): number

hasHeader

  • hasHeader(name: string): boolean

header

  • header(field: any): this
  • header(field: string, value?: string | string[]): this
  • Parameters

    • field: any

    Returns this

  • Parameters

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

    Returns this

links

  • links(links: any): this

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns Function[]

location

  • location(url: string): this
  • 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 this

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: "close", listener: () => void): this
  • on(event: "drain", listener: () => void): this
  • on(event: "error", listener: (err: Error) => void): this
  • on(event: "finish", listener: () => void): this
  • on(event: "pipe", listener: (src: Readable) => void): this
  • on(event: "unpipe", listener: (src: Readable) => void): this
  • on(event: string | symbol, listener: (...args: any[]) => void): this

once

  • once(event: "close", listener: () => void): this
  • once(event: "drain", listener: () => void): this
  • once(event: "error", listener: (err: Error) => void): this
  • once(event: "finish", listener: () => void): this
  • once(event: "pipe", listener: (src: Readable) => void): this
  • once(event: "unpipe", listener: (src: Readable) => void): this
  • once(event: string | symbol, listener: (...args: any[]) => void): this

pipe

  • pipe<T>(destination: T, options?: undefined | { end?: undefined | false | true }): T
  • Type parameters

    • T: WritableStream

    Parameters

    • destination: T
    • Optional options: undefined | { end?: undefined | false | true }

    Returns T

prependListener

  • prependListener(event: "close", listener: () => void): this
  • prependListener(event: "drain", listener: () => void): this
  • prependListener(event: "error", listener: (err: Error) => void): this
  • prependListener(event: "finish", listener: () => void): this
  • prependListener(event: "pipe", listener: (src: Readable) => void): this
  • prependListener(event: "unpipe", listener: (src: Readable) => void): this
  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this

prependOnceListener

  • prependOnceListener(event: "close", listener: () => void): this
  • prependOnceListener(event: "drain", listener: () => void): this
  • prependOnceListener(event: "error", listener: (err: Error) => void): this
  • prependOnceListener(event: "finish", listener: () => void): this
  • prependOnceListener(event: "pipe", listener: (src: Readable) => void): this
  • prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this
  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this

rawListeners

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

    • event: string | symbol

    Returns 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: () => void): this
  • removeListener(event: "drain", listener: () => void): this
  • removeListener(event: "error", listener: (err: Error) => void): this
  • removeListener(event: "finish", listener: () => void): this
  • removeListener(event: "pipe", listener: (src: Readable) => void): this
  • removeListener(event: "unpipe", listener: (src: Readable) => void): this
  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this

render

  • render(view: string, options?: undefined | object, callback?: undefined | ((err: Error, html: string) => void)): void
  • render(view: string, callback?: undefined | ((err: Error, html: string) => void)): 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 | ((err: Error, html: string) => void)

    Returns void

  • Parameters

    • view: string
    • Optional callback: undefined | ((err: Error, html: string) => void)

    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

  • sendStatus(code: number): this
  • 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 this

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

    • path: string
    • fn: Errback

    Returns void

  • deprecated

    Use sendFile instead.

    Parameters

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

    Returns void

set

  • set(field: any): this
  • set(field: string, value?: string | string[]): this
  • 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 this

  • Parameters

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

    Returns this

setDefaultEncoding

  • setDefaultEncoding(encoding: string): this

setHeader

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

setMaxListeners

  • setMaxListeners(n: number): this

setTimeout

  • setTimeout(msecs: number, callback?: undefined | (() => void)): this
  • Parameters

    • msecs: number
    • Optional callback: undefined | (() => void)

    Returns this

status

  • status(code: number): this
  • Set status code.

    Parameters

    • code: number

    Returns this

type

  • type(type: string): this
  • 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 this

uncork

  • uncork(): void

vary

  • vary(field: string): this
  • 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 this

write

  • write(chunk: any, cb?: undefined | ((error: Error | null | undefined) => void)): boolean
  • write(chunk: any, encoding: string, cb?: undefined | ((error: Error | null | undefined) => void)): boolean
  • Parameters

    • chunk: any
    • Optional cb: undefined | ((error: Error | null | undefined) => void)

    Returns boolean

  • Parameters

    • chunk: any
    • encoding: string
    • Optional cb: undefined | ((error: Error | null | undefined) => void)

    Returns boolean

writeContinue

  • writeContinue(callback?: undefined | (() => void)): void

writeHead

  • writeHead(statusCode: number, reasonPhrase?: undefined | string, headers?: OutgoingHttpHeaders): this
  • writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this
  • Parameters

    • statusCode: number
    • Optional reasonPhrase: undefined | string
    • Optional headers: OutgoingHttpHeaders

    Returns this

  • Parameters

    • statusCode: number
    • Optional headers: OutgoingHttpHeaders

    Returns this

writeProcessing

  • writeProcessing(): void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc