res.type(type)
This method is used to set the Content-Type header.
Example
res.type('html'); // => 'text/html'
res.type('json'); // => 'application/json'
res.type('application/json'); // => 'application/json'
res.type('png'); // => image/png:
index.js
'use strict' const express = require('express') const app = express() app.get('/', (req, res) => { res.type('html') res.status(200).send('<h1>Hello World<h1>') }) 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.
No comments:
Post a Comment