Nw.js: process.cwd() returns wrong path

Created on 18 Apr 2013  Â·  26Comments  Â·  Source: nwjs/nw.js

Shouldn't process.cwd() return the directory the user is currently at? It seems to always return the path where the app source lives regardless of where the user is running it from.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Most helpful comment

The problem still exists. Are there some clues for its solution?

All 26 comments

Thanks for reporting. Yes, it returns the current working directory. The reason the directory is not expected because we changed the working directory to app's root on start.

I'll see how to handle this.

I really need the right path as well.

No more?

I'd like to add my vote here, being able to get the current directory is important to me too.

In my current application, I'd like to use it to find a configuration file.

(Side note: this is my second choice, I wanted to get the arguments from the command line using nconf, but that isn't working because nconf always gets the command line arguments from process.argv).

I remembered, a few month ago, I came across this problem,either, finally, I used process.env.PWD and it worked very well.

Alas! That won't work under Windows.

We wouldn't want things to get too easy, now would we ...

+1

When I run nw app/, process.cwd() return the right path.
But after i package my app with grunt-node-webkit-builder, the process.cwd return a wrong path.

It should not return like this:

C:\Users\ADMINI~1\AppData\Local\Temp\nw7936_5644 

It should return: (nw.exe is in test folder)

C:\Users\Administrator\test

Do I miss something important?
How to fix it?

yes,I want to get the current directory that command from.
app.nw:

console.log(process.cwd());
copy /b nw.exe+app.nw d:/app.exe
cmd:
cd e:/project/www
d:/app.exe set.ini

I hope it return "e:/project/www". how to do?
please.

@purplestone
use process.execPath instead of process.cwd().
See https://github.com/rogerwang/node-webkit/issues/1877

@scarletsky

process.execPath return "AppDataLocalTemp" directory, It's not my current directory that command from.

@purplestone
I think you can use process.cwd() when you debug your app, and use process.execPath when you distribute it.

@scarletsky

I hope my code is the same in different environments. And process.execPath return "AppDataLocalTemp" directory,in my release exe package. I need the string that "cd/pwd" command output.

The expectation is that process.cwd() return the directory that the user initiated the application from. An application installed via npm link behaves incorrectly.

$ cd /home/usr/Notes/
$ myapp
"Current Working Directory: /home/user/Development/myapp/"

I am playing around with a 3-way merge tool, which needs to receive relative paths to the various versions of the file being merged in order to integrate with things like SourceTree. This bug makes that hard to achieve.
For scenarios/platforms where process.env.PWD contains the desired value, I have put the following in my index.html as a workaround:

    <script type="text/javascript">
      process.chdir(process.env.PWD);
    </script>

I believe this works for mac and linux - but not for windows.

@lsim Were you able to find a solution that also works for Windows?

Sorry, no. I haven't yet had reason to try. What I have done in the mean
time is to switch to atom shell. I can't say for certain it doesn't have
this weakness (or others like it), but I like it so far and am not going
back to nw.js
On Jun 8, 2015 10:08 PM, "Donald Hruska" [email protected] wrote:

@lsim https://github.com/lsim Were you able to find a solution that
also works for Windows?

—
Reply to this email directly or view it on GitHub
https://github.com/nwjs/nw.js/issues/648#issuecomment-110122541.

The problem still exists. Are there some clues for its solution?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

for me on mac process.cwd() or execPath returns path like this:

/private/var/folders/5f/2w5ss9tn6ksgwmxkl1lrqyyh0000gn/T/AppTranslocation/8C45F9CD-87C6-4902-8D10-6586815A15B6/d/Myapp.app/Contents/Resources

@rogerwang This is really hard to work around as an app developer. Could you implement a quick fix, such as storing the original working directory in a variable somewhere we can access it before NW.js changes the working directory?

Will provide a way. Thanks.

I love nw.js, but this has been an absolute plague to me. It is the biggest weakness in nw.js I have found in a year of using it. The second biggest problem is the lack of a reliable packaging solution.
I develop on Linux and distribute on Windows and (regrettably) Mac.

This is fixed in git and will be available in the next nightly build. nw.App.startPath is provided for the start working directory.

T Hanks!

On Tue, May 22, 2018 at 1:57 AM, Roger Wang notifications@github.com
wrote:

This is fixed in git and will be available in the next nightly build
http://dl.nwjs.io/live-build/. nw.App.startPath is provided for the
start working directory.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/nwjs/nw.js/issues/648#issuecomment-390883236, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAUmIrk2MffwDa--HyHUolsqB8PNXt4cks5t07bygaJpZM4AljbT
.

Thanks, this fix is really appreciated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bambooCZ picture bambooCZ  Â·  3Comments

xland picture xland  Â·  3Comments

ezruneko picture ezruneko  Â·  4Comments

xzh-loop picture xzh-loop  Â·  3Comments

imyzf picture imyzf  Â·  4Comments