How to Install NodeJS Modules Globally
Prerequisites:
- Installation of NodeJS.
- Knowledge of NodeJS.
- Knowledge of Windows Command Prompt.
The running working solution is provided.
Download Now!
npm config --global set prefix "D:\Program Files\nodejs\npm_pkgs" npm config --global set cache "D:\Program Files\nodejs\npm-cache"
By default NodeJS on windows machine install the global modules within the User profile's path. So, in a long run this will bulk up your drive C, which we do not want.
4) Next, use below command to install "moment" module globally for NodeJS i.e.
npm install moment -g
The module "Moment" provides rich features to manipulate date/time formats.
5) Once the module has been installed globally, Create your sample code in a file and name it index.js.
6) Then open windows command prompt again. You can open it without administration privileges. Then type below command first in order to create the link of the globally installed module within your targeted project i.e.
npm link moment
7) Now, type below command to execute the code and you will be able to see following i.e.
node index.js
Conclusion
In this article, you will learn to install NodeJS modules globally on windows 10/11 machine. You will also learn to change the global modules installation paths of NodeJS in order to save the memory of drive C and finally, you will learn to link the globally installed module with your project in order to run your code.