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.

This talk has been presented at DevOps.js Conf 2021, check out the latest edition of this JavaScript Conference.

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'.

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.

'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.

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
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
WebAssembly enables optimizing JavaScript performance for different environments by deploying the JavaScript engine as a portable WebAssembly module. By making JavaScript on WebAssembly fast, instances can be created for each request, reducing latency and security risks. Initialization and runtime phases can be improved with tools like Wiser and snapshotting, resulting in faster startup times. Optimizing JavaScript performance in WebAssembly can be achieved through techniques like ahead-of-time compilation and inline caching. WebAssembly usage is growing outside the web, offering benefits like isolation and portability. Build sizes and snapshotting in WebAssembly depend on the application, and more information can be found on the Mozilla Hacks website and Bike Reliance site.
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
The talk discusses the importance of supply chain security in the open source ecosystem, highlighting the risks of relying on open source code without proper code review. It explores the trend of supply chain attacks and the need for a new approach to detect and block malicious dependencies. The talk also introduces Socket, a tool that assesses the security of packages and provides automation and analysis to protect against malware and supply chain attacks. It emphasizes the need to prioritize security in software development and offers insights into potential solutions such as realms and Deno's command line flags.

Workshops on related topic

Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Top Content
Featured Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
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 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.