Question: What is the equivalent javascript code for `mysql_real_escape_string()`?

Answer: 
I've had an use case where I need to escape my own data (not from user input) in order to use it within a node.js script. I've fixed the code from @majinnaibu answer, because it was only escaping the first occurrence of the special symbol.

```
function mysqlEscape(stringToEscape){
    if(stringToEscape == '') {
        return stringToEscape;
    }

    return stringToEscape
        .replace(/\\/g, "\\\\")
        .replace(/\'/g, "\\\'")
        .replace(/\"/g, "\\\"")
        .replace(/\n/g, "\\\n")
        .replace(/\r/g, "\\\r")
        .replace(/\x00/g, "\\\x00")
        .replace(/\x1a/g, "\\\x1a");
}

```

Hope this helps someone else.
I think we can use escape() methode