What's New in npm?

Rate this content
Bookmark

The npm CLI has been, & continues to be, a core developer tool of the Node.js/JavaScript ecosystem. This past year npm@7 became Generally Availble, introducing with it a wealth of changes & net-new capabilities including: lockfile upgrades, workspace support, installing peer dependencies default, npm diff, npm explain, npm exec, npm set-script & much, much more. We'll dive into this work as well as share some exciting news about what to expect in the weeks & months to come.

FAQ

NPM CLI is a command-line interface tool that helps developers install, manage, and publish their software packages on the NPM registry. It supports various functionalities, including package installation, building, testing, and more.

NPM CLI version 7 introduced several new features such as automatic installation of peer dependencies, enhanced performance for installation commands, workspace support, and new commands like 'npm explain' and 'npm diff'. Additionally, improvements were made to existing commands including 'npm audit' and 'npm exec'.

'npm explain' is a command in NPM CLI that provides information about why a specific package is installed, detailing dependencies and their relationships within your project. It helps developers understand package usage and dependency management better.

As of NPM CLI version 7, peer dependencies are installed automatically by default. This change aims to simplify dependency management for developers, reducing the need to manually resolve and install these dependencies.

In version 7, 'npm audit' received a significant overhaul in its logic, performance, and user interface. These changes are designed to make the audit process quicker and easier for developers to understand, helping them identify and resolve vulnerabilities more efficiently.

Workspace support in NPM CLI allows developers to manage multiple packages within a single project efficiently. As of version 7, the initial implementation of workspace support primarily affects the 'npm install' command, with plans to expand this to other commands in future releases.

NPM CLI version 6 will continue to receive security updates as necessary until the last Node.js LTS version that depends on it reaches end-of-life. However, new features and non-critical updates will primarily be implemented in newer versions of the CLI.

Darcy Clarke
Darcy Clarke
26 min
01 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Welcome to my talk on what's new in the NPM CLI. NPMv7 introduced many new capabilities, including installing peer dependencies by default. npm v7 also introduced support for workspaces, allowing the definition of projects within your root project. The NPM team is continuously improving the CLI with weekly releases and is working on exciting features in collaboration with GitHub. NPM is not an acronym for Node Package Manager, and the CLI will continue to improve with the support of the growing team.

Available in Español: ¿Qué hay de nuevo en npm?

1. Introduction to NPM CLI

Short description:

Welcome to my talk on what's new in the NPM CLI. NPM is known for installing packages, with almost 125 billion monthly package downloads. But we also support discovery, building, bundling, testing, and more. Our team has grown, with new members and nearly 700 contributors. NPMv7 introduced many new capabilities, including installing peer dependencies by default.

Welcome, everybody. Thank you for joining me today. My name is Darcy Clark, and I'm going to be talking about what's new in the NPM CLI. I want to give a big shout out and that's been running the conference so far and all the folks behind the scenes at DevOpsJS 2021.

A quick overview on who I am. I'm the engineer manager for the NPM CLI team at GitHub. I'm based here in Toronto, Ontario, Canada, and there's a bunch of other places that you can find me on the interwebs.

So, I want to start with talking a little bit about what NPM does or what people think we do. And I think the biggest thing we're known for is installing a whole bunch of packages, so this is our average package download count. I think last time I checked, we're almost at 125 billion package downloads monthly as a community, which is a pretty amazing mark. I think we had about 100 billion average monthly downloads back in September, October, October, around the 11th anniversary of the 11th year of NPM, which is pretty cool. We do more than just install packages and publish packages. So the NPM CLI supports also discovery, building and bundling your packages, testing, and a whole bunch of other features with a number of commands. And if you're looking for information on the 61 plus commands and growing, you can go check out our docs at docs.npmjs.com. You'll notice that they just recently got a nice new design, a refresh, and there's a ton of information about the config as well as the commands that we support.

So what has changed in the NPM CLI? Because you might be wondering, I switched tooling a while back. What has changed or what's new in the NPM CLI? Well, what's changed quite a bit is our team. Over the last couple of years, we've added and had new folks join our team. Currently we have a core team of myself, Roy Adorno, Nathan Lafreniere, and Michael Garvan, our GAR. We're also expanding this team and adding three new folks come next month. And we also get a ton of contributors, almost 700 contributors to the NPM CLI, which is pretty amazing. What's also changed is that we just recently shipped NPMv7 and went latest or sort of generally available in January 2021. So, in v7 we introduced a lot of new capabilities, including some improvements to legacy commands and also added things like workspace support along with much, much more. So, let's dive into some of these changes. So as a v7, one of the biggest things that you'll note is that we've started to install peer dependencies by default. Peer dependencies are not new by any stretch of the imagination, they've been around for about eight years. But what we noticed is that a lot of projects were starting to have to, and a lot of developers are starting to have to manually manage these dependencies, which is a problem. NPM is a package manager and we want to manage your packages. So in this example, you can see that I have two workspace projects that actually depend on different versions of react. These are essentially conflicting versions, and we don't quite know what we...

2. New Features and Improvements in npm v7

Short description:

Previously, in v7, we now install and resolve peer dependencies, providing warnings and actionable steps if we can't. The logic for this resolution has been moved to a new package called Arborist. We also introduced npm explain, which shows why a package was installed. npm exec now asks for confirmation before installing new packages. npm audit has been refactored for easier vulnerability management. npm diff allows you to see the difference between package versions. npm v7 introduced a new package lock schema and improved performance.

Previously, we would just leave these be and let the developers essentially manage these. As a v7, we will now try to do our best to install and resolve your peer dependencies. And if we can't, we'll print a sort of a warning with some actionable steps for you to take to essentially resolve these dependencies. And if you're looking for the actual logic that is running and doing this resolution, we've moved everything that we... Sort of the brains of the operations into a net new package that we call Arborist.

So moving on, we actually introduced, to sort of help with this change, we also introduced npm explain, or the alias npmy. And this command actually functions a lot similar to yarn's npmy and npm explain, where it will actually show you the reason why a package was installed. So in this case, I've run npm explain chalk, and asking essentially, why is chalk installed, and npm will let you know that in this case, I have a workspace project called b, and it actually includes chalk as a peer dependency, and that's the reason why that got installed. So some nice developer, you know, experience and developer tooling to sort of help with ergonomics around managing your dependencies.

Also, what's kind of new npm exec was introduced in v7. It's essentially the guts of npx. So if you've ever used npx, then this will be, you know, not very new to you. We added some safeguards with npm exec and npx. In v7, we now actually ask before installing a package we've never seen before, we actually ask you to confirm and have a confirmation prompt to ensure that you don't accidentally install something and run something that you didn't mean to.

So also as of v7, we've made significant changes to npm audit. npm audit got sort of a an entire refactor in terms of the logic, performance, and also ui. So now we hope that it's a lot easier for developers to quickly grasp what exactly is going on and what the flags are for the different dependencies that might have a vulnerability issued against them. And we hope that this is actually a way faster experience for developers and we think it's an improved experience overall for sure. And a net new command that we actually introduced just recently is npm diff. With npm diff, it works very similar to get diff in that you can actually specify a package name, a version or a file and you can essentially see the difference between those two things. This is great. In this example I'm essentially seeing what's changed between two different versions of my package called sleepover and I can see that the version was updated and the package json was changed slightly.

Another big change in npm v7 was the introduction of a new package lock schema. Previously we were on v1 of the package lock and as you transition or as you upgrade to npm v7 we will seamlessly upgrade your version of your package lock file to meet essentially this new schema. So there shouldn't be any problems with upgrading and if you have any problems with developers using v6 or v7 you can always say no save or provide the flag no save to not update your package lock files. So another huge win that we sort of accomplished with npm v7 was some improvements to the actual performance of a lot of the commands. Specifically on install we initially saw a sort of a degradation but we noted that we were actually installing more dependencies because of the changes in behavior that we had introduced with peer dependencies. So peer dependency resolution bumped out some of our install times because we're actually installing and resolving more dependencies so this was somewhat expected, and as you can see we've started to benchmark across different sort of scenarios and fixtures including installing peer depths. So that's that last benchmark there at the bottom. As we sort of move forward we actually saw that we made actual significant improvements against ourselves and are hoping to continue this work inside of the benchmark suites that we're running and are hoping to continue to focus on performance as a place for us to optimize and get better.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
Do you have a large product built by many teams? Are you struggling to release often? Did your frontend turn into a massive unmaintainable monolith? If, like me, you’ve answered yes to any of those questions, this talk is for you! I’ll show you exactly how you can build a micro frontend architecture with Remix to solve those challenges.
Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
Learn more about how to leverage the default features of npm workspaces to help you manage your monorepo project while also checking out some of the new npm cli features.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
Remix is a web framework that gives you the simple mental model of a Multi-Page App (MPA) but the power and capabilities of a Single-Page App (SPA). One of the big challenges of SPAs is network management resulting in a great deal of indirection and buggy code. This is especially noticeable in application state which Remix completely eliminates, but it's also an issue in individual components that communicate with a single-purpose backend endpoint (like a combobox search for example).
In this talk, Kent will demonstrate how Remix enables you to build complex UI components that are connected to a backend in the simplest and most powerful way you've ever seen. Leaving you time to chill with your family or whatever else you do for fun.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
JavaScript in the browser runs many times faster than it did two decades ago. And that happened because the browser vendors spent that time working on intensive performance optimizations in their JavaScript engines.Because of this optimization work, JavaScript is now running in many places besides the browser. But there are still some environments where the JS engines can’t apply those optimizations in the right way to make things fast.We’re working to solve this, beginning a whole new wave of JavaScript optimization work. We’re improving JavaScript performance for entirely different environments, where different rules apply. And this is possible because of WebAssembly. In this talk, I'll explain how this all works and what's coming next.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
As developers, we spend much of our time debugging apps - often code we didn't even write. Sadly, few developers have ever been taught how to approach debugging - it's something most of us learn through painful experience.  The good news is you _can_ learn how to debug effectively, and there's several key techniques and tools you can use for debugging JS and React apps.
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
Do you know what’s really going on in your node_modules folder? Software supply chain attacks have exploded over the past 12 months and they’re only accelerating in 2022 and beyond. We’ll dive into examples of recent supply chain attacks and what concrete steps you can take to protect your team from this emerging threat.
You can check the slides for Feross' talk here.

Workshops on related topic

Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.
Node.js Masterclass
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Top Content
Workshop
Matteo Collina
Matteo Collina
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.

Level: intermediate
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.
Build a powerful DataGrid in few hours with Ag Grid
React Summit US 2023React Summit US 2023
96 min
Build a powerful DataGrid in few hours with Ag Grid
WorkshopFree
Mike Ryan
Mike Ryan
Does your React app need to efficiently display lots (and lots) of data in a grid? Do your users want to be able to search, sort, filter, and edit data? AG Grid is the best JavaScript grid in the world and is packed with features, highly performant, and extensible. In this workshop, you’ll learn how to get started with AG Grid, how we can enable sorting and filtering of data in the grid, cell rendering, and more. You will walk away from this free 3-hour workshop equipped with the knowledge for implementing AG Grid into your React application.
We all know that rolling our own grid solution is not easy, and let's be honest, is not something that we should be working on. We are focused on building a product and driving forward innovation. In this workshop, you'll see just how easy it is to get started with AG Grid.
Prerequisites: Basic React and JavaScript
Workshop level: Beginner
Build and Deploy a Backend With Fastify & Platformatic
JSNation 2023JSNation 2023
104 min
Build and Deploy a Backend With Fastify & Platformatic
WorkshopFree
Matteo Collina
Matteo Collina
Platformatic allows you to rapidly develop GraphQL and REST APIs with minimal effort. The best part is that it also allows you to unleash the full potential of Node.js and Fastify whenever you need to. You can fully customise a Platformatic application by writing your own additional features and plugins. In the workshop, we’ll cover both our Open Source modules and our Cloud offering:- Platformatic OSS (open-source software) — Tools and libraries for rapidly building robust applications with Node.js (https://oss.platformatic.dev/).- Platformatic Cloud (currently in beta) — Our hosting platform that includes features such as preview apps, built-in metrics and integration with your Git flow (https://platformatic.dev/). 
In this workshop you'll learn how to develop APIs with Fastify and deploy them to the Platformatic Cloud.
0 to Auth in an Hour Using NodeJS SDK
Node Congress 2023Node Congress 2023
63 min
0 to Auth in an Hour Using NodeJS SDK
WorkshopFree
Asaf Shen
Asaf Shen
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool.
We will enhance a full-stack JS application (Node.JS backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:- User authentication - Managing user interactions, returning session / refresh JWTs- Session management and validation - Storing the session for subsequent client requests, validating / refreshing sessions
At the end of the workshop, we will also touch on another approach to code authentication using frontend Descope Flows (drag-and-drop workflows), while keeping only session validation in the backend. With this, we will also show how easy it is to enable biometrics and other passwordless authentication methods.
Table of contents- A quick intro to core authentication concepts- Coding- Why passwordless matters
Prerequisites- IDE for your choice- Node 18 or higher