Termux

On Termux, when requiring a npm package installed globally (with npm install -g package-name) in a JS file, if it returns ‘not found, you may try this solution.

Check whether this command returns empty:



echo $NODE_PATH


If it is empty, then run these commands:



which npm

which node


Outputs returned by them:

➜  ~ which npm  
  
/data/data/com.termux/files/usr/bin/npm  
  
➜  ~ which node                      
  
/data/data/com.termux/files/usr/bin/node  

Now change which node path

from:  
/data/data/com.termux/files/usr/bin/node  
  
to:  
/data/data/com.termux/files/usr/lib/node_modules

You append this command to your Terminal .bashrc so that it will automatically export this whenever you run Termux:

export NODE_PATH=/data/data/com.termux/files/usr/lib/node_modules

Restart Termux and re-run your JS code.

Ubuntu in Termux

Need to use this export:

export NODE_PATH=/usr/local/lib/node_modules  

export NODE_PATH=/usr/local/lib/node_modules

n conclusion: cd to the mentioned path, and run ls to see whether there is any module dirs.

ls /usr/local/lib/node_modules