npm is a package manager for NodeJS based environments. It is one of the most important tools you need to set up and efficiently manage JavaScript projects. To waste less time on project setup and focus better on the actual code, npm is the go-to for any JavaScript developer. One of the prerequisites to develop great node projects is to learn npm.
Below is a detailed guide to the best available resources for learning this tool. We’ll cover books, video courses, and professional guides, and community-generated content so that you can pick the learning path that best suits your needs.
How to learn npm
Before diving into the specifics of the tool, it is important to gain a bird’s eye view of its dynamics and uses. npm is relevant only to JavaScript-based projects. If you are aiming to build something using flask, Django, or Golang, npm is no use for you. Let’s take a look at the tool in detail before we move on to the available resources for learning it.
What is npm?
Npm is a command-line tool, bundled with the node.js installation, and can be used to initialize new node projects. With a package manager like npm, it is easy to install and manage these packages.
The inception of npm is a story worth sharing. When node.js was introduced, it brought the possibility of using JavaScript in server runtime environments. The combination of V8 JavaScript runtime and C++ made node extremely fast. However, the focus of node shifted gradually from just server-side applications to a wider array of JavaScript tools for automation and utilities. Packages like webpack and Babel, Gulp came up as people slowly started exploring the true potential of Node.
A big void that remained was the question of “how would these tools be generalized across all JavaScript runtimes?” This is where package managers like npm came in. It generalized the process of managing these packages. There are other alternatives to npm, like yarn and pnpm, but they are out of the scope of this article.
What is npm used for?
There are several uses of npm in a node-based project’s lifecycle. Let’s take a quick look at some of them:
- Setting up a fresh project. A node project contains some boilerplate code, to begin with. Usually, it is just the package.json file that identifies a location as a node project. In some cases, the default requirements of a new project can be much more than the package.json file alone. Npm accommodates these requirements and provides a quick and simple method of initializing new projects.
- Installing dependencies. When you are working on a project, you might need to install third-party dependencies. Even something as fundamental as the React library needs to be manually installed if you are setting up a fresh React project. npm simplifies this process, by providing a very handy command to quickly install and uninstall dependencies.
- Automating repetitive tasks. Running tasks in a generic project development process is repetitive. More often than not, it is required to lint your code before pushing it to the main repo. Other times, tests are mandatory before signing off a git commit. These tasks can always be done manually, but npm provides a shortcut. You can define these commands in the form of scripts in your package.json files. Then, these scripts can be assigned to specific keywords, like run, or build.
- Publishing your packages. npm has out-of-the-box support for the npmjs.com repository of globally available node packages. This means building and publishing your packages is easy. You need only a few commands to help get your package online.
- Compatibility with GitHub: Apart from the npmjs.com repository of node packages, npm also has support for GitHub packages. This means if you have a GitHub repository with a GitHub Package associated with it, you can publish your npm package and pull it in your local projects as a dependency.
Learning npm
Given that npm is such a versatile tool, it is important to periodically brush up on it. Following is a list of resources to help you get started as a beginner in npm.
The Best npm Resources
As npm is a tool in the JavaScript ecosystem, a lot of community-generated content is available for it. Before we take a look at that, here are a few great video courses to help get you started:
- Platform: Udemy
- Duration: 40 minutes
- Price: Free
- Prerequisites: None
- Start Date: On-demand
With a 4.4-star rating by over 1,500 students, this course stands out from the crowd. Since it is free as well as on-demand, it makes up the best possible video resource for absolute beginners. This 40-minute course is broken down into 16 videos, covering each subtopic for about 3 minutes. This helps learners to easily refer to the content on any of the subtopics of npm.
NPM crash course by Traversy Media
- Platform: YouTube
- Duration: 42 minutes
- Price: Free
- Prerequisites: None
- Start Date: On-demand
This is one of the most concise courses available on the topic, which touches all necessary subtopics of npm, providing ample information on them. If you are looking for a course that can give you a walkthrough of all aspects of npm, as well as be short enough to refer back to whenever needed, this is the one. On the plus side, Traversy Media has a great reputation for creating beginner-friendly courses.
- Platform: Pluralsight
- Duration: 1 hour
- Price: Pluralsight subscription needed
- Prerequisites: None
- Start Date: On-demand
The NPM Playbook has a 4.5-star rating by over 350 students. It is a recommended course to take up if you have prior experience with npm. The course provides great insight on what goes under the hood when working with the npm CLI.
npm Books
Apart from video courses, many books are available to help you get started with npm. Some top ones include:
‘ABeginner’s Guide to npm, the Node Package Manager’ by SitePoint
Priced at $4.99, the book covers the basics of npm in great detail. It also has a live preview available here. The book also has a dedicated section on package.json, an important file in node-based projects. While many resources miss out on small details like version control of dependencies, this book has it all covered for you.
‘Learn using NPM’ by Rising Stack
Learn using NPM is a free e-book published by Rising Stack. It is a great resource for quickly skimming through the basics of the tool, as it is adequately short and concise. The e-book can be downloaded for free by entering your email address on the Rising Stack landing page.
npm Resources
Apart from learning via video courses and books, several great write-ups on npm are available online. Here is a list of great articles on npm:
- A NPM Crash Course by Robin Wieruch
- An Absolute Beginner’s Guide to Using npm by nodesource.com
- A Beginner’s Guide to npm, the Node Package Manager by SitePoint
Apart from the resources shared above, there are very few good ones available independently. The reason is that most of the standard Node.js courses cover npm as an independent chapter.
A developer is rarely required to learn npm outside the Node environment. This is why you can find some great videos or write-ups on npm inside Node-based courses. However, when it seems like they are not enough, you can always come back to this list to get some dedicated content on the topic.
How Long Does It Take to Learn npm?
Given npm’s simplicity in usability, it usually takes beginners about 10 days to get familiar with the tool. The key is to keep experimenting with the commands and keep practicing them in a dummy project while you are new to them.
Alternatively, you may try writing down a short list of the most important commands of npm with a one-line explanation next to them. You can stick this list on your desk on a post-it note, or create a virtual sticky note on your computer screen. This will come in very handy when you are looking for any commands that you can not recall. Here’s how a typical cheat sheet of npm commands would look like:
- Init – Initializes a new project
- install <package> – Installs the said package
- build – Runs the build script, defined in package.json
- start – Runs the start script, defined in package.json
- publish – Publishes local package to npmjs.org
- uninstall <package> – Uninstalls the said package
- run-script <script> – Runs the said script defined in package.json
Should you Learn npm?
After compiling a great list of courses and content on npm, we are now faced with the most important question of all: should you learn npm? The answer to this depends on many factors. If your day-to-day job involves building and writing JavaScript code, npm is one of the most important tools that you should have handy. If you aim to publish packages on the npm registry as well, there’s no other tool that would fit your use-case better.
Alternatively, if you are just looking to manage dependencies in your projects, you may want to explore alternatives like yarn and pnpm. This is because yarn and pnpm turn out to be better than npm in terms of speed and security. That being said, npm remains the top tool to manage node projects, as it ships bundled with NodeJS.
"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"
Venus, Software Engineer at Rockbot
If you are ever going to work on node projects in any capacity, you are better off with some working knowledge of npm.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.