Nw.js: How to get the location of nw.exe?

Created on 12 Oct 2013  路  5Comments  路  Source: nwjs/nw.js

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?

Most helpful comment

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);

All 5 comments

 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jportoles picture jportoles  路  3Comments

chino23 picture chino23  路  3Comments

imyzf picture imyzf  路  4Comments

bambooCZ picture bambooCZ  路  3Comments

xland picture xland  路  3Comments