Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get working directory in node-webkit

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.

like image 834
Szymon Wygnański Avatar asked May 23 '13 21:05

Szymon Wygnański


1 Answers

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.

like image 138
Ryan Q Avatar answered Sep 22 '22 08:09

Ryan Q