Changing contents of a text file

suggest change

Example. It will be replacing the word email to a name in a text file index.txt with simple RegExp replace(/email/gim, 'name')

var fs = require('fs');
 
fs.readFile('index.txt', 'utf-8', function(err, data) {
    if (err) throw err;
 
    var newValue = data.replace(/email/gim, 'name');
 
    fs.writeFile('index.txt', newValue, 'utf-8', function(err, data) {
        if (err) throw err;
        console.log('Done!');
    })
})

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents