Read all text from stdin to a string

前端 未结 4 1294
孤城傲影
孤城傲影 2020-12-16 09:26

I\'m writing a program in Node.js that (in some situations) wants to act as a simple filter: read everything from stdin (up to end of file), do some processing, write the re

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 09:54

    My boiler-plate for this one is a lot like the solution described in a comment above -- offering it at the top level because it's very much the simplest way to do this and it shouldn't be only in a comment.

    var fs = require('fs');
    var data = fs.readFileSync(0, 'utf-8');
    // Data now points to a buffer containing the file's contents
    

提交回复
热议问题