Manipulating the local file system with browser-based JavaScript and Node

Naturally, browser-hosted JavaScript cannot access the file system of the user’s machine (at present; someday, some kind of sandboxed access may happen — the last attempt failed, but that doesn’t mean the next one has to — the next attempt is in Chromium browsers now).

So to do this, you’ll need two pieces:

  1. A browser piece, which does the UI with the user.

  2. A Node piece, which runs on the user’s machine (and thus can access the file system) and which the browser piece uses to do the actual file operations.

Probably the easiest way for the pieces to interact would be HTTP, which you can trivially support using ExpressJS.

So for instance, if the user wants to delete a file:

  1. User clicks something to say “delete this file”
  2. Browser JavaScript sends the command to the Node process over HTTP via ajax
  3. Node process does the deletion and reports success/failure
  4. Browser JavaScript displays the result

Leave a Comment