I realised that when I did a global installation of a node.js module (with the -g flag) node couldn't use that module unless I wrote the entire path.
I mean, this doesn't work if the module has been globally installed:
cheerio = require('cheerio'),
I have to write that:
cheerio = require('/usr/lib/node_modules/cheerio'),
How can I say to node that it has to look for the modules in the right path?
Thank you.
Local installation It installs the packages in a node_modules subdirectory of the current working directory, usually a project folder.
js documentation and found that it can be changed very easily using a simple "npm config" command. For example: npm config set prefix "E:\node_modules", From the next time onward, every global installation will save the node modules in "E:\node_modules" folder.
Node. js path module is used for handling and transforming file paths. This module can be imported using the following syntax. var path = require("path")
The Path module provides a way of working with directories and file paths.
In general, I would suggest letting npm give you the path and set that as mentioned above:
$ echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile
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