Tuesday 19 March 2019

Express: res.status(code): Set the status code for the response


res.status(code)
This method sets the status code for the response.

Example
res.status(403).end();
res.status(400).send('Bad Request');
res.status(404).sendFile('/absolute/path/to/404.png')

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 res.status(200).send('Hello World')
})

const port = 3000
app.listen(port, () => console.log(`Application started listening on port ${port}!`))

Run index.js.


You can see below message.


Previous                                                 Next                                                 Home

No comments:

Post a Comment