javascript - Replacing URLs in html not working -


i want replace links in html file not working.

var fs = require('fs');  fs.readfile(__dirname + '/index.html', 'utf8', function(err, html){  if(!err){    html = html.replace('https://mysite1.github.io/', 'https://example.com/');   console.log(html);  }  else{console.log(err);}  }); 

can u me this? i'm bit new in nodejs/javascript

replace replaces first instance. need use regular expression replace all.

var fs = require('fs');  fs.readfile(__dirname + '/index.html', 'utf8', function(err, html){  if(!err){     var replacelink = "https://mysite1.github.io/";     var regex = new regexp(replacelink, "g");     html = html.replace(regex, "https://example.com/");     console.log(html);  }  else{console.log(err);}  }); 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -