Here is a problem I am having when using Node.js:
This is my code in index.js:
.....
app.get('/xyz', function(request, response) {
fs = require('fs');
fs.readFile('views/pages/xyz.ejs', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
response.render('pages/xyz', {result:data});
});
});
.....
Here is xyz.ejs:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="container">
<% displayStr=result.replace("\n", "<br/>"); %>
<%= displayStr %>
</div>
</body>
</html>
Here is what I get in my browser, when I point it to top/yxz :
<!DOCTYPE html><br/><html> <head> </head> <body> <div class="container"> <% displayStr=result.replace("\n", "<br/>"); %> <%= displayStr %> </div> </body> </html>
Even though there are line break tags (<br/>), I get a one long line text display instead of an HTML display.
I tried various things I could find, but nothing worked.
What should I do to obtain a normal display line by line?
xyz.ejsbe changed itself?