Read a file synchronously in Javascript

前端 未结 6 466
无人及你
无人及你 2020-12-08 01:49

I would like to read a file and convert it into a base64 encoded string using the FileReader object. Here\'s the code I use :


    var reader = new FileReader();
         


        
6条回答
  •  臣服心动
    2020-12-08 02:27

    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.

提交回复
热议问题