Skip to content Skip to sidebar Skip to footer

How To Write File With Node Webkit Js?

When I build my app, 'fs' module doesn't work. So, it must write file, but when I start my app nothing happens. But if I start my app with: $ /path/to/app nw It works correctly. W

Solution 1:

Try this:

Include the following (standard) module:

var path = require('path');

Specify the path as follows:

fs.appendFile(path.resolve(__dirname, './log.txt'), 'Checking problem 2: \n\n');

More info on the __dirname global can be found here.

EDIT

Since __dirname is not defined in node-webkit, you'll have to use the following workaround:

Make a file util.js or however you want to call it, containing this line:

exports.dirname = __dirname;

The __dirname variable can now be exposed in your main file:

var dirname = require('./util.js').dirname;

And replace __dirname by dirname in the code.

Details here

Post a Comment for "How To Write File With Node Webkit Js?"