nodejs - module installation

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,719
Reaction score
529
Hi,
I have been experimenting node js recently. I notice that npm with install the modules in the current directory in the node_modules folder. If the nodejs script that uses these modules and it's moved to another location, then the script will not work. Unless, the path is in require(). This is a messy approach. It would be best if all the modules are in one location. How to get npm install to put modules at a specific location and a fast way to indication the module location in require().

Thanks in advance.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Hi,
I have been experimenting node js recently. I notice that npm with install the modules in the current directory in the node_modules folder. If the nodejs script that uses these modules and it's moved to another location, then the script will not work. Unless, the path is in require(). This is a messy approach. It would be best if all the modules are in one location. How to get npm install to put modules at a specific location and a fast way to indication the module location in require().

Thanks in advance.

https://nodejs.dev/learn/npm-global-or-local-packages
Local installation is preferred if you want to have your application packaged in a self contain manner.

:)
 

Trader11

Banned
Joined
Oct 14, 2018
Messages
15,698
Reaction score
5,233
Hi,
I have been experimenting node js recently. I notice that npm with install the modules in the current directory in the node_modules folder. If the nodejs script that uses these modules and it's moved to another location, then the script will not work. Unless, the path is in require(). This is a messy approach. It would be best if all the modules are in one location. How to get npm install to put modules at a specific location and a fast way to indication the module location in require().

Thanks in advance.
As davidktw mentioned, follow the convention of installing project dependencies in local project directory and gitignore node modules.
 

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,719
Reaction score
529
Thanks folks.
I have to be mindful of the dependencies when I move the script to another location.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top