How to append new line character in node.js?

I'm sure the new line is there, but you aren't going to see it when you send your Content-Type as text/html. In HTML, \n is just other whitespace, and is treated as such. Use text/plain instead.


Since content type is 'text/html',we can happily use break statement.Just like this

res.write('hello'+'<br/>');
 res.write('nice to meet you');

You can try this code in node:

var http = require('http');

http.createServer(function (req, res) {

res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('hello,this is saikiran'+'<br/>');
res.end('nice to meet you');

}).listen(process.env.PORT || 8080);
console.log('server running on port 8080');