Send JSON response using Express

How to use Node.js Express library to provide JSON data

When you listen to the connection on the route in Express, the callback function will be called in each network call with a request object instance and a response object instance.

example:

app.get('/', (req, res) => res.send('Hello World!'))

Here we usedResponse.send()Method, it accepts any string.

You can sendJSON formatBy using to customersResponse.json(), A useful method.

It accepts an object or array and converts it to JSON before sending:

res.json({ username: 'Flavio' })

Download mine for freeExpress.js manual


More crash tutorials: