Linked Questions

Popular Questions

I wrote an API and the response from that API is array of data. Whenever the response coming from that API i want to store that response in file that is.txt format. I tried but it shows an error like "No such directory or NO such path". How to create file and write data into file from API using node.js. This is the code i wrote :

    exports.Entry = functions.https.onRequest((req, res) => {
      var fs = require('fs');
      var a = ['6', '7', '8'];
      var b = ['22', '27', '20'];
      var eachrecord = [];

      for (var i = 0; i < a.length; i++) {
        eachrecord += a + b;

      console.log("eachrecord is", eachrecord);

      //Writing each record value into file
     function fileWriteSync(filePath){
  var fd = fs.openSync(filePath,'w');
  var length = eachrecord.length;
  for(i = 0;i<length;i++){
    var eachrecordwrite = fs.writeSync(fd,eachrecord[i] + '\n',null,null);



How to write data into file from API using node.js

Related Questions