node js : save entered line breaks to mysql?

How should I save the user-entered line breaks from a text area to MYSQL database in nodejs?

I'm trying to save every word space and line-breaks from textarea. I am trying to save the result from db in the following way

in textarea :

First line
second line

I am getting the result in this manner

first%20linesecond%20line

i want the result in db to look like in the following format in the text area...

I know that if it was in php I could have used nl2br() like http://id1.php.net/nl2br But i want to know and use it in nodejs.

How should I do it?

So, basically, you will have to replace all your '\r\n', '\r' and '\n' to <br /> before inserting the value into the database.

temp = "First Line\nSecond Line"
temp.replace('\n','<br />')

I have never worked in nodejs, but this should work in js environment.

function nl2br (str, is_xhtml) {
  var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br ' + '/>' : '<br>';     
  return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}

Reference