javascript - how to write file with node webkit js? -
when build app, 'fs' module doesn't work. so, must write file, when start app nothing happens. if start app with:
$ /path/to/app nw
it works correctly. what's wrong?
some code, use fs:
function check_prob_2(){ console.log('problem 2'); fs.appendfile('log.txt', 'checking problem 2: \n\n'); ... }
i use function, doesn't work. doesn't work after build application. build this guide
try this:
include following (standard) module:
var path = require('path');
specify path follows:
fs.appendfile(path.resolve(__dirname, './log.txt'), 'checking problem 2: \n\n');
more info on __dirname global can found here.
edit
since __dirname not defined in node-webkit, you'll have use following workaround:
make file util.js
or want call it, containing line:
exports.dirname = __dirname;
the __dirname variable can exposed in main file:
var dirname = require('./util.js').dirname;
and replace __dirname
dirname
in code.
details here
Comments
Post a Comment