Monday, 18 March 2019

Express: res.send([body]): Send http response


res.send([body])
Send the response to the client. Response body can be a Buffer object, a String, an object, or an Array.

Example
res.send(new Buffer('whoop'))
res.send({ some: 'json' })
res.send('<p>some html</p>')
res.status(404).send('Sorry, we cannot find that!')
res.status(500).send({ error: 'something blew up' })

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 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’



Previous                                                 Next                                                 Home

No comments:

Post a Comment