0

here is my code:

var fs = require('browserify-fs');

this.state = {

      idList: [],
};

    Submit = (event) => {
    const { idList } = this.state;
    //const {print} = fs.writeFile('C:/Users/Shreyas Joshi/Desktop/Transil-Internship/node-server-upload/uploads/idList.txt', idList, function(err) {});
    fs.mkdir('C:/Users/Shreyas Joshi/Desktop/Transil-Internship/ABHINAV/general-template', function() {
      fs.writeFile('C:/Users/Shreyas Joshi/Desktop/Transil-Internship/ABHINAV/general-template/idList.txt', idList, function() {
          console.log("written to file!");

      });
  });
    this.setState({
    });

  }

It is entering the fs.writeFile() function and printing to console "written to file!" but nothing is getting written into the file. Can someone please solve this issue or suggest a better way to do this.Thank You.

  • You cannot write to arbitrary files on the host from the browser. The data is likely stored in some in-memory storage. – Felix Kling Mar 15 '19 at 06:29
  • so what do i do? How do i print it to a text file? – Shreyas Joshi Mar 15 '19 at 06:36
  • 1
    You have to write to a file from a server, for example Node.js one. Not React, because frontend-side javascript don't have such rights – flppv Mar 15 '19 at 06:39
  • Maybe this helps: [Create a file in memory for user to download, not through server](https://stackoverflow.com/q/3665115/218196) – Felix Kling Mar 15 '19 at 06:53

0 Answers0