How do you read a file or Stream synchronously in node.js?

前端 未结 1 1459
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 23:19

Please, no lectures about how I should be doing everything asynchronously. Sometimes I want to do things the easy obvious way, so I can move on to other work.

For som

1条回答
  •  不思量自难忘°
    2021-02-06 23:22

    To read the contents of a file synchronously use fs.readFileSync

    var fs = require('fs');
    var content = fs.readFileSync('myfilename');
    console.log(content);
    

    fs.createReadStream creates a ReadStream.

    0 讨论(0)
提交回复
热议问题