Other than grabbing the package.json file at the project root is there a way to determine the list of dependencies of a running node.js application? Does node keep this meta information available as some var in the global namespace?
Other than grabbing the package.json file at the project root is there a way
Share
If you are just looking for the currently installed npm packages in the application directory, then you can install the npm package (
npm install -g npm) and programatically invokelsto list the installed packages and the dependency trees.Obviously, this has no bearing on whether the installed packages are actually
require‘d in the application or not.Usage is not that well documented but this should get you started.
e.g.:
Otherwise, I believe the only other option is to introspect the
modulemodule to get information pertaining to the currently loaded/cached module paths. However this definitely does not look to have been developed as a public API. I’m not sure if there are any alternatives so would be keen to hear if there are e.g.