Home > other >  res.write() - text on web page all on one line - node.js
res.write() - text on web page all on one line - node.js

Time:04-06

All the text shows up on one line and it includes the <br/ >.

res.write("stuff"   "<br/>"   "more stuff");
res.write("words <br/> more words");
res.send();

output =

stuff<br/ >more stuffwords <br/ > more words

why are the breaks not working? Seems to work for everyone suggesting to do so but me lol I know I'm missing something easy, I just can't figure it out...

CodePudding user response:

Please add res.setHeader("Content-type", "text/html"); before your res.write.

By default content-type is not set to text/html. express example

CodePudding user response:

try this:

res.setHeader("Content-type", "text/html");
res.write(`
  stuff
  <br />
  more stuffwords 
  <br /> 
  <p>more words</p>
`);
res.send();
  • Related