Manoj
Manoj

Reputation: 390

How to save the data to local system in electron main window

I want to store and write the data to the local system file which is entered in the text box given in the electron window

Is it possible to achieve this using the electron App ? enter image description here

Upvotes: 0

Views: 3895

Answers (1)

Jens Habegger
Jens Habegger

Reputation: 5446

This can be achieved using the standard node.JS filesystem API:

var fs = require('fs');
var content = "sample text file content";
fs.writeFile("/folder/filename.txt", content, function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("File succesfully saved to disk.");
}); 

The Node Filesystem API can be a bit overwhelming, you could check out helper packages like fs-jetpack, which offer some user-friendly abstractions.

Additionally, the Electron API offers a method called dialog.showSaveDialog to determine the filepath using a dialog window.

Upvotes: 2

Related Questions