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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -