Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find native modules in a node.js dependency tree?

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?

like image 834
obelix Avatar asked Mar 16 '16 09:03

obelix


People also ask

How do I check Nodejs modules?

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.

What are native modules Nodejs?

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.

How do you read an npm dependency tree?

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 .

Where does node look for node_modules?

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.


2 Answers

There's a native-modules CLI package for this.

$ npx native-modules

screenshot

like image 200
Tamlyn Avatar answered Oct 19 '22 17:10

Tamlyn


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
like image 42
mscdex Avatar answered Oct 19 '22 15:10

mscdex