Friday 15 March 2019

Express: res.end([data] [, encoding]): End the response process


res.end([data] [, encoding])
This method ends the response process.

Example
res.write('Dear User, Welcome to node.js web developement.')
res.write('I hope, you are enjoying the express module')
res.status(200).end();

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
 res.send('Hello World')
})

app.get('/welcomeKit', (req, res) => {
 res.write('Dear User, Welcome to node.js web developement.')
 res.write('I hope, you are enjoying the express module')
 res.status(200).end();
})

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

Run index.js


Open the url ‘http://localhost:3000/welcomeKit’ in browser, you can see below message.


Previous                                                 Next                                                 Home

No comments:

Post a Comment