I tried process.cwd() but I'm getting some weird location : C:\Users\Dinesh\AppData\Local\Temp\nw2300_31612
nw.exe is at the location : C:\Users\Dinesh\Programs\Node-Webkit\Package
why is this difference in the paths and how can I get the location of nw.exe?
path.dirname(process.execPath);
Node-Webkit extracts the *.nw file to the temporary directory so that temporary directory is the current working directory. You can use side by side packaging method to keep the working directory to the folder where nw and package.json file resides.
As @xdenser has mentioned you can use
var path = require('path');
var nwPath = process.execPath;
var nwDir = path.dirname(nwPath);
how to do the side by side packaging?
Putting the package.json file and nw.exe in same folder without compressing.
sorry for necro'ing an almost 3-year old thread, but it seems there still isn't a way of getting the source of the exe without side by side packaging, so building upon @Subash's code, we can do:
var path = require('path');
var nwPath = process.argv[0];
var nwDir = path.dirname(nwPath);
then nwDir should be the one the user originally opened, not the unpacked one from temp folders
Most helpful comment
Node-Webkit extracts the
*.nwfile to the temporary directory so that temporary directory is the current working directory. You can use side by side packaging method to keep the working directory to the folder where nw and package.json file resides.As @xdenser has mentioned you can use