Monday, 11 March 2019

Express: res.append(field [, value]): Append response header


res.append(field [, value])
This method appends specified value to the given response header field.

Example
res.set('tempInforamtion', 'basicUser')
res.append('tempInforamtion', 'Session for 30sec')
res.append('tempInforamtion', 'roles: admin&supervisor')

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 res.set('tempInforamtion', 'basicUser')
 
 res.append('tempInforamtion', 'Session for 30sec')
 
 res.append('tempInforamtion', 'roles: admin&supervisor')
 
 res.send('Hello World')
})

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 the header tempInformation.


You can even pass multiple values to header as an array.
res.append('tempInforamtion', ['Session for 30sec', 'roles: admin&supervisor'])

Note

if you call res.set() after res.append(), then it will reset the previously set header values.

Previous                                                 Next                                                 Home

No comments:

Post a Comment