Languages
[Edit]
EN

Express.js - send response with status

3 points
Created by:
Rogan-Wilkes
727

In this article, we would like to show you how to send response with status using Express.js.

Quick solution:

or:

Where: send() method can be replaced by any method from response API.

 

Response API

Edit

In this section you can find most common methods used in response API.

MethodDescription
send()Sends indicated data as response, e.g. 'Response message!'.
json()Sends the object as JSON.
jsonp()Sends the object as JSONP.
download()Transfers the file as "attachment".
sendFile()Transfers the file as response content, e.g. index.html.
etc.Other methods are available here.

 

Practical example

Edit

In this example, we present how to use status() and json() methods to send JSON response with status 200 on HTTP GET request.

 

References

Edit
  1. res.status(code) - Express.js API
  2. res.sendStatus(statusCode) - Express API
  3. Response - Express.js API

Alternative titles

  1. Express.js - send response with specific status code
  2. Express.js - set status code in response
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join