Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Properties

charset: string
headersSent: boolean

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');

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: Record<string, any>

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

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');

Methods

  • 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 "/home/runner/work/forge/forge/node_modules/webpack-dev-server/node_modules/http-proxy-middleware/dist/types".Response

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

    Parameters

    • field: string

    Returns undefined | string

  • 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 "/home/runner/work/forge/forge/node_modules/webpack-dev-server/node_modules/http-proxy-middleware/dist/types".Response

  • 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('back'); 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

  • deprecated

    use res.redirect(status, url) instead

    Parameters

    • url: string
    • status: number

    Returns void

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

          • err: Error
          • html: string

          Returns void

    Returns void

  • Parameters

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

          • err: Error
          • html: string

          Returns void

    Returns 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.headersSent 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

    Returns void

  • Parameters

    Returns void