In this beginner guide to NPM, we will cover what exactly it is, how it works & a couple of commonly used NPM commands which you can start using right away in your projects.
With NPM, you don't have to go manually downloading, installing & setting up the package. NPM take cares of everything so that you can focus on your project.
NPM has an official website which you should definitely bookmark. On the website, you can find all the npm packages available for you to use. The packages also have great documentation which you can follow on how to install and use in your project.
Not just that but if you wish, you can also publish and share your own packages on this platform which then will be available for anyone to use.
You can visit the official website here - www.npmjs.com
Working with npm is super easy, all you need is to make sure that Node JS is installed in your system. NPM comes pre-installed with Node JS so you don't have to worry about installing it manually. Once you've successfully installed Node JS, you can simply use any command-line interface like a terminal to run npm commands, install npm packages from the npm registry and start using npm in your projects.
If you are using npm in your project then there are two very important files associated with npm that you should know about.
node_modules- It's a directory automatically created in the root folder of your project which will contain all the npm packages you install locally. One more thing you should note here that this directory will be automatically ignored by git and will not appear in your project's repo.
package.json- It is a file that is again automatically created in the root directory of your project which contains metadata about the packages you have installed.
Both of these files are created automatically & are managed by npm so you don't have to worry about them until you're experienced enough to manually work on them.
This command initializes npm in your project and will automatically create the package.json file.
This command is simply an alteration of
npm init which just skips a few unnecessary steps and creates the package.json file quickly.
This command will install the specified package locally and add it into the package.json as a dependency.
This command is again an alteration of the
npm install command which will install the specified package but on a system-wide or global scale.
This command is used to update a specified package to its most recent release available.
This command is used to update all the packages present in the package.json file at once to their most recent versions available.
This command lists all the packages installed in your system.
This command is used to uninstall the specified package which you no longer need.
This command will uninstall the specified package globally.
Thank you so much for reading! I hope you learnt something new today. Please leave a like, a lovely comment or feedback & also consider following me as I regularly post useful & informative articles to help you become a better programmer.
If you like my work please consider Buying me a Coffee so that I can bring more projects, more articles for you.