Reputation: 23
Can someone please help me find the location of standard NodeJS modules like http
or fs
?
When I write:
const http = require('http');
Where is the module coming from? For NPM this is easy to find, but strangely I can't find http.js
or any other standard library file.
Upvotes: 2
Views: 1869
Reputation: 63
Unlike third-party dependencies Nodejs built-in modules like http or fs are bundled with the node binary that you have installed. This has to do with optimization so that they run faster.
One way to find them is in the source code of Node. You can go to the node official repo and find http
and fs
under the lib
directory.
Upvotes: 0
Reputation: 13
Well this depends on which operating system you are using:
If you are on windows it's in C:\Program Files\nodejs\node_modules\npm\node_modules
or at least I think...
If you want to know on linux check out this question on the askubuntu.com website. In this question, someone answered that it was in
/usr/local/lib/node or /usr/local/lib/node_modules
There is a high chance that on mac, the location is the same as linux because macOS is based upon some "ancient" linux dist.
EDIT : If you have a custom installation path then (of course) nodeJS is in the folder you unpacked it. You can also check your user/system variables aka environment variables.
Upvotes: 1
Reputation: 1124
The actual running node location can be found with this command
node -e "console.log(process.execPath)"
this will output the executed bin compiled nodejs path. which will not really much help you.
what will help you is knowing the node version you are running and check the source code of the module you want. http.js .
or debug nodejs in real time. break point on the http module and then get into the module itself with the help of the debugger. check out this guide
Upvotes: 1