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

前端 未结 1 1458
伪装坚强ぢ
伪装坚强ぢ 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)
提交回复
热议问题