How do I get the path to the current script with Node.js

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

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?

Answers

http://nodejs.org/docs/latest/api/globals.html#globals_dirname http://nodejs.org/docs/latest/api/globals.html#globals_dirname

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/3133243/how-do-i-get-the-path-to-the-current-script-with-node-js

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils