1

I must make a local app with an interface. This app should load text files, modify them, and save them.

I made the interface with html/css/js, and the core of the app was made with js only.

Currently, I load the file with an input, but to save it, the browser makes me download it. I know this is a security measure.

This app is not going to be put online.

My question is : what can I do to replace directly the loaded file by the new one ?

  • Can I use my app (html/css/js) without a browser ?
  • Is there a browser that allows me to edit my local files directly ?
  • Is there any solution I can't think of ? Using another language to communicate with the js maybe ?

Thanks.

Abcdef GHI
  • 115
  • 2
  • 8
  • please provide the code you have tried – user93 Jun 21 '17 at 09:46
  • 1
    You should look at [Electron](https://electron.atom.io/), and then see [this](https://stackoverflow.com/questions/38067298/saving-files-locally-with-electron) – Serge K. Jun 21 '17 at 09:47
  • @user93 To download the file ? Something close to [this](https://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript/32858416#32858416). – Abcdef GHI Jun 21 '17 at 10:09
  • @NathanP. I will definitely try this afternoon. – Abcdef GHI Jun 21 '17 at 10:09
  • Several browsers now support the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API), which can be used to modify files on the local disk. – Anderson Green Feb 15 '22 at 22:47

2 Answers2

1

If you don't need your app to be online, with Electron you can make an executable using your existing code (you will have change how you're going to save the file using Electron APIs). Being a program running on your system, you'll be able to save directly on the file system.

Roberto Russo
  • 834
  • 10
  • 22
0

JS in the browser is not able to edit local files, because of security.

If you want to, you can use Node.js, a Desktop/Server Framework, which uses JS.

Christoph Pader
  • 158
  • 3
  • 13
  • I don't know Node enough to see how it could help. Could you tell me very quick what could be done and how using Node ? – Abcdef GHI Jun 21 '17 at 10:06
  • Node.js is just the framework, which let's you run JS on the Desktop/Server. Depending on your needs, you could use other frameworks like Electron (Desktop & Mac), Cordova & Ionic (Smartphone), which are also based on Node.js – Christoph Pader Jun 21 '17 at 10:23
  • If you need a GUI, i would recommend using Electron, it's simple to use and very well structured – Christoph Pader Jun 21 '17 at 10:24