tags:

views:

24

answers:

1

How would I get the path to the script in node.js? I know there's process.cwd, but that only refers to the directory where the script was called, not of the script itself. For instance, say I'm in /home/kyle/ and I run the following command:

node /home/kyle/some/dir/file.js

If I call process.cwd(), I get /home/kyle/, not /home/kyle/some/dir/. Is there a way to get that directory?

+2  A: 

Ok, found it after looking through the documentation again. What I was looking for are the __filename and __dirname global variables.

Kyle Slattery