Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js modules path

Tags:

node.js

npm

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.

like image 993
Mario Avatar asked Nov 20 '12 02:11

Mario


People also ask

Where are node js modules installed?

Local installation It installs the packages in a node_modules subdirectory of the current working directory, usually a project folder.

How do I give a path of node modules?

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.

What is the path module in node js?

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")

What is path module used for?

The Path module provides a way of working with directories and file paths.


1 Answers

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 
like image 102
inki Avatar answered Sep 29 '22 07:09

inki