I'm building an app using nodejs.
I created a form, and I'm working on back-end validation of user input. Basically, I have a var, "messages", and each time I encounter an input error, I append the error to messages.
var messages ="";
errors.forEach(function(msgObject) {
console.log(msgObject.message);
messages += msgObject.message + "\r\n";
})
(I'm also using indicative -- http://indicative.adonisjs.com/ -- for error validation. It returns an array errors)
I'm returning the errors to the user using connect-flash
req.flash("error", messages);
I'm using connect-flash https://www.npmjs.com/package/connect-flash
My problem is that connect-flash ignores newline characters. I.e, I get something like:
I would like each error message to be on a separate line. I can't seem to find a way to accomplish that. Any ideas?
Here's a simpler version of the problem: Why does req.flash("errors", "hello \n goodbye") return
hello goodbye
instead of
hello
goodbye