Starting Now: iLoveCoding courses are completely FREE. No login or signup required.

NPM - Node Package Manager

Node.js's growth is partially attributed to NPM (Node Package Manager). Anyone, including you, can create a small piece of functionality and make it into a module. People all over the world have created millions of modules and made it publicly accessible for all of us to use. This speeds up coding tremendously. Lets learn how to leverage its power

FREELevel: Intermediate7:55 mins
Course content

What is Node Package Manager

In this lesson, we are going to look at what is NPM, how to use it and why to use it 

NPM stands for Node Package Manager, it is a piece of software that comes packaged with node. Node is a separate piece of software. Node is the runtime for JavaScript. NPM is a separate piece of software that helps you import modules inside node and you use them.

If you go to the website you will see they have over 200k packages in the NPM directory. These packages can be used to speed up your development. One of the most popular one is called Express.js which really helps you build web applications. with node js faster.

If you want to know which version of npm you have, simply go to the console or terminal and write npm –v and it will tell you the exact version. You can also do the same for node as well by writing node –v 

Your NPM module can be installed in two separate places. You can install your NPM in your local area or in your project files. Let’s create a folder and call it someProject and in the terminal go inside the folder by writing cd (filename) in our case it’s going to be cd someProject and inside that folder we are going to create a script.js file where you can write code.

So write touch script.js this is how you create a file inside a folder via the terminal. The modules can be installed in the project folder. Or NPM modules can also be installed in the global directory.

You can see the list of modules available in your project that you downloaded from a github or anywhere. Write npm ls in the terminal and hit enter. Currently there isn't any module in the folder as you can see below. 


If you want to see the modules installed on your computer, you can simply write npm ls -g  g is for global. Hit enter and you will see there are so many modules which comes pre-installed with Node in the global directory. So in our case, the modules are stored in the /usr/local/lib folder. In your case it may be different


If we go the our lib directory, you can see there are only 10 modules but inside those modules there are sub modules and the list goes on and on.


If you want to install any particular module in your project folder, you can simply write npm install (filename) if you want to install express module, you can write npm install expresshit enter and you see the express module is not installed. 


You can remove any module as well by writing npm rm (filename so if we want to remove the express module we can write npm rm expresshit enter and it will remove the module. If you want to install the same module globally, you can write npm install express -g or that doesn't work for some reason try writing sudo npm install express -gyou can also remove that as well by writing sudo npm rm express -g. You can also install specific editions. You can define the version like such sudo npm install express@4.11.1 -gI hope you enjoyed this lesson. If you have any questions, leave your comments below. I'll talk to you in the next lesson. Good bye :)

Become a confident software developer with mentor support!
Get Started
Already have an account? Please Login