Skip to content Skip to sidebar Skip to footer

How To Get The Current Directory For An Nw.js Executable

Struggling to find the current directory when I create an nw.js executable. I have created a Mac server application with a mix of html and Javascript and a lot of node.js module us

Solution 1:

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 (Putting the package.json file and nw.exe in same folder without compressing) method to keep the working directory to the folder where nw and package.json file resides. You can use the following to get the current path

var path = require('path');
var nwPath = process.execPath;
var nwDir = path.dirname(nwPath);

Solution 2:

For Windows use: var path = require('path'); path.dirname(process.execPath);

For Mac and Linux use: global.__dirname;

Post a Comment for "How To Get The Current Directory For An Nw.js Executable"