Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the node.js install path from code

Tags:

node.js

I'm trying to write a debugging framework for node.js and am having a hard time figuring out how to get the full path to a core module file like fs.js.

I've heard it's in the /lib folder of the node installation, but I'd need to get this from the code in a consistent way for a variety of install situations (including windows).

I've tried taking a look at the process and process.env values for something like a node install path but can't see anything that immediately pops out at me.

like image 325
Jacob Avatar asked Oct 03 '12 18:10

Jacob


1 Answers

To find where the installed node executable is located you can look at the process.execPath which gives the absolute path to Node executable.

To find where a certain module is located you can use require.resolve(module);

However I think the global modules are not directly accessible from the filesystem as other regular modules since they seem to be cached somewhere within the executable.

like image 197
DeadAlready Avatar answered Oct 05 '22 16:10

DeadAlready