I am looking to output the contents of a text file to a webpage using node.js. I have managed to get the text from the file and have been able to use it together with some basic HTML to render a page but the text has lost all its formatting and is rendered as one long string:
i.e. the contact.txt file has the following in it:
Peter
Robert
Bob
but when I use fs.readFile I get the following on my page:
Peter Robert Bob
Does anyone know how to preserve the line breaks in the original text file? The code I am using follows
fs.readFile('contact.txt', (error, txtString) => {
if(error) throw err;
console.log(txtString.toString());
res.write(
'<div id="content">'+ txtString.toString()
);