I have a node.js application with about 10 direct dependencies which result in a total of 50 dependencies.
I would now like to know if any of these dependencies use native code (apart from that of the node.js platform itself of course), such as external system libraries (I've seen libxml used in other projects), own C/C++ libraries, node-gyp build scripts which need compilers installed etc. etc.
Is there an easy/quick way to check the whole dependency tree of a given module for such cases?
The core modules are defined within the Node. js source and are located in the lib/ folder. Core modules can be identified using the node: prefix, in which case it bypasses the require cache.
In node, most modules are written in javascript. Some modules, like the fs module are written in C/C++, as you can't edit files from plain javascript. IIRC, these modules are called 'native' because the code for these modules is slightly different depending on the OS node runs on.
Use the npm list to show the installed packages in the current project as a dependency tree. Use npm list --depth=n to show the dependency tree with a specified depth. Use npm list --prod to show packages in the dependencies . Use npm list --dev to show packages in the devDependencies .
Node will look for your modules in special folders named node_modules . A node_modules folder can be on the same level as the current file, or higher up in the directory chain. Node will walk up the directory chain, looking through each node_modules until it finds the module you tried to load.
There's a native-modules CLI package for this.
$ npx native-modules
You could simply search for *.node
files, which is the extension used by compiled addons:
find node_modules -type f -name "*.node" 2>/dev/null | grep -v "obj\.target"
If you want to check what shared libraries each addon uses, you could use something like:
find node_modules -type f -name "*.node" 2>/dev/null | grep -v "obj\.target" | xargs ldd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With