How to read from stdin line by line in Node

前端 未结 8 1437
闹比i
闹比i 2020-11-28 01:47

I\'m looking to process a text file with node using a command line call like:

node app.js < input.txt

Each line of the file needs to be proce

8条回答
  •  日久生厌
    2020-11-28 02:38

    // Work on POSIX and Windows
    var fs = require("fs");
    var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0
    console.log(stdinBuffer.toString());
    

提交回复
热议问题