var fs = require('fs'); var fileDy="index.vue"; var str=fs.readFileSync(fileDy).toLocaleString(); console.log(str) let re = /row1/gi; //var str = 'row1 are round, and apples are juicy.'; var newstr = str.replace(re, 'row2'); console.log(newstr) fs.writeFile('index1.vue',newstr,function(err){ if (err) { console.log('-----------error-------------') } })