Noob Noob - 1 year ago 92
HTML Question

Html.Replace is not working in Node

I have following code:

var html=fs.readFileSync(__dirname +'/index.htm','utf8');
var message='Template';


And below id html file in which I want to replace
but its not working.

<!DOCTYPE html>



This is what I get while debugging:


Answer Source

From the MDN docs for String.prototype.replace():

The replace() method returns a new string with some or all matches of a pattern replaced by a replacement.

This means that your original string will remain unchanged, and the call to replace() will return a new string with the replacement made.

Try updating your code with this line:

html = html.replace('{Message}',message);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download