Saturday, 16 March 2019

Express: res.json([body]): Send json response


res.json([body])
This method is used to send the json response.

         res.json({
                  'name' : 'Chat Server',
                  'varsion' : "1.29.3"
         });

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 res.json({
  'name' : 'Chat Server',
  'varsion' : "1.29.3"
 });
})

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 message.


Previous                                                 Next                                                 Home

No comments:

Post a Comment