Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving files locally with electron

I have some template files that contain a few variable strings each, I'd like to build a very simple input form with Electron (https://www.electronjs.org/) and I want to save the composed output file on the user's computer.

Is there any module I can use to let Electron save files locally?

like image 216
Adriano Avatar asked Jun 28 '16 04:06

Adriano


People also ask

Can Electron access local files?

Read & Write Local FilesOne great benefit of using Electron is the ability to access the user's file system. This enables you to read and write files on the local system.

What is FS readdirSync?

The fs. readdirSync() method is used to synchronously read the contents of a given directory.


1 Answers

If you are targeting multiple platforms, I answered a similar question here. Basically app.getPath(name), app.setPath(name, path), and app.getAppPath() are very useful in saving files to the the right place regardless of the OS.

You may also want to check out these Nodejs packages which help simplify saving files directly to the host machine...

  • fs-jetpack
  • graceful-fs
  • Node.js fs

If you intend for users to save files you might also have a look at the Dialog api where you can specifically invoke a save dialog for that purpose.

like image 147
Josh Avatar answered Sep 20 '22 13:09

Josh