Alta istar Alta istar - 1 year ago 104
Node.js Question

How to remove one line from a txt file

I have the following text file ("test.txt") that I want to manipulate in node.js:


I want to remove the first line so that
becomes the first line instead. How can I do that?

Answer Source
var fs = require('fs')
fs.readFile(filename, 'utf8', function(err, data)
    if (err)
        // check and handle err
    var linesExceptFirst = data.split('\n').slice(1).join('\n');
    fs.writeFile(filename, linesExceptFirst);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download