Reputation: 237
I'm using Express 4 with Node JS, below is my code:
const express = require('express');
const router = express.Router();
router.get('/socket', (req, res, next) => {
res.send('<p>Hello</p>');
});
But it shows the following
instead of rending the p tag, what am I doing wrong?
Upvotes: 6
Views: 12325
Reputation: 5
To get h1 header in output, you can use the following code here i have used 3 const to demonstrate their use with it
const express = require('express');
const router = express.Router();
router.get('/socket', (req, res, next) => {
const city="Londan";
const country="England";
const temp=24;
res.send("<h1>Hello, The temperature in "+city+","+country+" is "+temp+"</h1>");
});
use " nodemon app.js " to run server " ctrl + c " to end a server.
Upvotes: -2
Reputation: 518
res.send().
Sends a string response in a format
Try this
> res.write('<h1>Hello, World!</h1>');
res.send
can only be called once in a code, but it is same as res.write
+ res.end()
Upvotes: 2
Reputation: 2358
res.setHeader('Content-type','text/html')
set the header before sending response.
Upvotes: 15