Browserify with require('fs') Browserify with require('fs') node.js node.js

Browserify with require('fs')


If you want to inline file contents from fs.readFileSync() calls, you can use brfs:

var fs = require('fs');var src = fs.readFileSync(__dirname + '/file.txt');

then do:

browserify -t brfs main.js > bundle.js

and src will be set to the contents of file.txt at compile time.


If you want to run file system with browserify you can install npm.

npm install browserify-fs 

and you can access fs object on client side.
Thanks


Which filesystem should the browser use then? The HTML5 filesystem is not really comparable to a traditional filesystem. It doesn't have symlinks, and it is only accessible asynchronously outside Web Workers.

So the answer is: Write an abstraction layer yourself that can rely on the fs module when running in Node.js, and the HTML5 FS API when running in the browser. The differences are too large to have browserify translate for you.