Saturday 9 March 2019

Express: res.headersSent: Check whether response headers send to the client or not


res.headersSent
This property used to check whether response headers are sent to the client or not.

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 console.log(`Is headers sent ? : ${res.headersSent}`)
 res.send('Hello World')
 console.log(`Is headers sent ? : ${res.headersSent}`)
})

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

Run index.js

Open the url ‘http://localhost:3000/’ in browser, you can see below messages in console.
Is headers sent ? : false
Is headers sent ? : true



Previous                                                 Next                                                 Home

No comments:

Post a Comment