How to get working directory in node-webkit

Szymon Wygnański picture Szymon Wygnański · May 23, 2013 · Viewed 9k times · Source

I've got a simple program that can be run from command line. This program is for live preview of markdown files. When i'm packaging the app with

cat $NW/nw marknow.nw > marknow

and running from different location:

./build/marknow ../relative/path/to/file.md

I can't get current working directory.

process.cwd()

is returning /tmp/something???

How can I get working directory in node-webkit? Directory from which ./build/marknow ../relative/path/to/file.md was called.

Answer

Ryan Q picture Ryan Q · May 24, 2013

Another option you could try if the cwd doesn't seem to work is getting the execution directory with something like this:

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

This should get you the execution directory of the exe. cwd gets the temp directory because of how node-webkit handles opening the files from a temp directory on each run.