0

If I run a node script in C:\temp in Windows how do I find out what directory that script is running from, (how do I find the path to where the script itself is located in the filesystem?)

The fs module documentation doesn't seem to hold an answer to this.

2 Answers 2

3

__dirname should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

1

process.cwd() will give you current working directory.

4 Comments

Apologies, but I down-voted this because it had an upvote and yet the OP specifically asked to know what directory the script is running in, which __dirname is guaranteed to do, and process.cwd() is not. And I guess my assumption (insert old joke here) is that the OP meant he wanted to know the directory of the script file itself.
@barry-johnson Yeah that was kind of a vague way of asking the question...but now we know the answer to two questions... :-p Maybe it should be split into two questions and two answers.
I actually didn't think it was terribly vague myself. If you had asked where node was running from, as opposed to your script, I would have presumed you wanted the cwd. But yes, you are indeed now twice as informed. :-)
@Sociopath If you want credit for the other question, it's here to be answered: stackoverflow.com/questions/22213792/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.