Search code examples
node.jsbrowserify

Why can I not see files created with browserify-fs on my Mac though I can read them with browserify-fs


For simplicity's sake, I'll use the example given on the browserify-fs package page, though the exact same thing happens when I use a file I've created myself. The write appears to work because the read appears to read the file, spewing out its contents via console.log. I've tried rebooting my machine and running just the read to make sure the file isn't lurking about in memory, and still the read works. Yet no amount of seaching shows me the file actually on my disk - not even in the 'home' directory which appears to be empty. Any thoughts?


fs.mkdir('/home', function() {
    fs.writeFile('/home/hello-world.txt', 'Hello world!\n', function() {
        fs.readFile('/home/hello-world.txt', 'utf-8', function(err, data) {
            console.log(data);
        });
    });
});```

Solution

  • It's due to security. Browser doesn't have permission to write files to local machine. See this - Manipulating the local file system with browser-based JavaScript and Node