Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the current directory #5618

Closed
RichardFoss opened this issue Jan 7, 2017 · 4 comments
Closed

Getting the current directory #5618

RichardFoss opened this issue Jan 7, 2017 · 4 comments
Labels

Comments

@RichardFoss
Copy link

RichardFoss commented Jan 7, 2017

Struggling to find the current directory when I create an executable.

I have created a Mac server application with a mix of html and Javascript and a lot of node.js module usage. I have two xml files that the server accesses and that reside in the same folder as the application.

When I run the application as follows:
./nwjs.app/Contents/MacOS/nwjs .
and find the current directory as follows:
var workingFolder = process.cwd();
then my working folder is the one where the application and xml files reside.

However, if I follow the 'package and distribute' guidelines (create a .nw file, name it app.nw, and put in contents/resources), and then run the .app executable, I get the following as the working folder:
/private/var/folders/3x/2hq40kzs59q8gj6yfn4ktj940000gn/T/.io.nwjs.nw.HcwnF2

I assume that the context changed. So I have been looking at alternatives to get the current directory. I tried:
var workingFolder = global.__dirname;
and got the same result. Then:
var workingFolder = process.env.PWD;
and got undefined (although this worked for the 'unpackaged' version)

How do I get the current directory?

Any ideas would be much appreciated!

@CosmoMyzrailGorynych
Copy link

CosmoMyzrailGorynych commented Jan 10, 2017

global.__dirname and process.cwd() point to the folder where your package.json is placed. If you've packaged your app, this will usually be a random temporary folder with the full source of your application and package.json.

process.execPath shows instead the path of your execuatable file (nw itself). You can use such snippet to get this directory:

const path = require('path');
console.log(path.dirname(process.execPath));

Also, there exists nw.App.dataPath, which points to user's data folder of your application. This one is the most constant one.

@RichardFoss
Copy link
Author

Thank you very much Cosmo! The directory I get is:
/Users/richardfoss/Documents/ImmergoTest/Immergo.app/Contents/Versions/5‌​0.0.2661.75/nwjs Helper.app/Contents/MacOS
I had previously renamed nwjs.app to Immergo.app. I now just search for Immergo.app and take the directory slice.
I would like to better understand the packaging process. For example, why nwjsHelper is called? If you know where there is documentation for this, I would appreciate it. Thanks again, Richard.

@CosmoMyzrailGorynych
Copy link

If you know where there is documentation for this

Afaik these are the only information about packaging:

http://docs.nwjs.io/en/latest/For%20Users/Package%20and%20Distribute/
https://github.com/nwjs/nw.js/wiki/How-to-package-and-distribute-your-apps

@RichardFoss
Copy link
Author

Yes, that is where I got my info from. It looks as if this book has quite a bit of packaging info:
https://www.manning.com/books/cross-platform-desktop-applications
Also, as I understand there is work being done to package for Mac App Store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants