Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node-Webkit: How to create a file in the local file system?

With using Node-Webkit, I'm trying to create and write to a text file in a user defined local folder from within a web worker js file. I tried using requestFileSystemSync(), .root.getFile(), .createWriter(), etc. but I'm not sure where this file is saved (can it be written to an defined local folder, or is it "sandboxed" to a special folder location?).

Can anyone offer advice on the best way for me to create text files from a web worker to an arbitrary local folder location? That is, in the local file system outside of a sandboxed file system?

Thanks.

like image 904
cohoman Avatar asked Aug 07 '13 03:08

cohoman


1 Answers

It sounds like you might be trying to use the web filesystem API. That might be a reasonable solution, it would allow you to run your app as a regular webpage, however the web filesystem API is sandboxed.

node-webkit offers "Complete support for Node.js APIs," which I think means you can use the node.js file system API to write anywhere on the file system. Pretty cool. So something like this should work:

var fs = require('fs');
fs.writeFile("path/to/anywhere/test.txt", "Hi mom!", function(err) {
    if(err) {
        alert("error");
    }
});

Also, node-webkit web-workers do not support require I hear. So you'll need to do your filesystem stuff in your main thread.

like image 119
Nathan Breit Avatar answered Oct 19 '22 16:10

Nathan Breit