The Developer's Guide to Updating npm Packages (2024)

The Developer's Guide to Updating npm Packages (1)

The Developer's Guide to Updating npm Packages (2)

Alexandru Năstase

Posted on • Updated on • Originally published at alexandrunastase.com

The Developer's Guide to Updating npm Packages (3) The Developer's Guide to Updating npm Packages (4) The Developer's Guide to Updating npm Packages (5) The Developer's Guide to Updating npm Packages (6) The Developer's Guide to Updating npm Packages (7)

TLDR: How to upgrade npm packages?

The simplest way is to install npm-check-updates, run npx ncu, followed by npx ncu -u to update the package.json followed by npm install to update packages in package.lock and node_modules.

Vanilla npm approach

npm comes with the tools to upgrade your packages out of the box. When running npm outdated you can get a list of packages that have available updates:

The Developer's Guide to Updating npm Packages (8)

We can update individual packages by running npm update {package-name}. Let's try it for the last package on the list:

npm update sass

Now if we run npm outdated again we can (as seen in the image below) that the package was indeed updated. One thing to note is that while package.lock was updated package.json remains untouched.

The Developer's Guide to Updating npm Packages (9)

Now we could do the same for all the packages and if you have a production-critical application, you probably want to pay close attention to the packages that you upgrade and the implications that an upgrade could have.

Upgrades using npm-check-updates

Another option, that I find slightly more convenient, especially for more low-risk projects is using the npm-check-updates package. To install it simply run:

npm install -g npm-check-updates

After it's installed we can check for updates by running:

npx ncu

Similar to npm outdated this gives us a list of all available updates:

See Also
Yarn

The Developer's Guide to Updating npm Packages (10)

In order to update one single package we can run:

npx ncu -uf sass

followed by:

npm install

Now if we run npx ncu again we see the sass package was updated:

The Developer's Guide to Updating npm Packages (11)

What is nice about the npm-check-updates package is that we can also update all of the packages if we choose so by running:

npx ncu -u

followed again by

npm install

Now if we run npx ncu again we get:

The Developer's Guide to Updating npm Packages (12)

Now both package.json and package.lock were updated, so this makes it clearer what version of the packages we have without the need to look into the package.lock file.

Conclusion

If you want to easily upgrade all your packages you can use the npm-check-updates npm package with the commands shown above, otherwise, you can also use npm's built-in commands npm outdated and npm update.

References:

Cross-posted from my blog: The joy of implementing strategy pattern in Symfony

Top comments (0)

Subscribe

For further actions, you may consider blocking this person and/or reporting abuse

The Developer's Guide to Updating npm Packages (2024)
Top Articles
Lamborghini Urus Interior Layout & Technology | Top Gear
Digital Nomad Statistics & Trends: 2023 & 2024 | Localyze
Nullreferenceexception 7 Days To Die
The UPS Store | Ship & Print Here > 400 West Broadway
Craigslist Campers Greenville Sc
oklahoma city for sale "new tulsa" - craigslist
Poe Pohx Profile
Women's Beauty Parlour Near Me
Ashlyn Peaks Bio
Barstool Sports Gif
Was sind ACH-Routingnummern? | Stripe
C-Date im Test 2023 – Kosten, Erfahrungen & Funktionsweise
Craigslist Alabama Montgomery
Scholarships | New Mexico State University
Where does insurance expense go in accounting?
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
2024 U-Haul ® Truck Rental Review
979-200-6466
Lawson Uhs
Foxy Brown 2025
Beryl forecast to become an 'extremely dangerous' Category 4 hurricane
Acts 16 Nkjv
Drug Test 35765N
Costco Gas Hours St Cloud Mn
Skycurve Replacement Mat
Synergy Grand Rapids Public Schools
Nk 1399
Duke University Transcript Request
Busch Gardens Wait Times
LG UN90 65" 4K Smart UHD TV - 65UN9000AUJ | LG CA
Why comparing against exchange rates from Google is wrong
Perry Inhofe Mansion
Duke Energy Anderson Operations Center
Moses Lake Rv Show
Roto-Rooter Plumbing and Drain Service hiring General Manager in Cincinnati Metropolitan Area | LinkedIn
House Of Budz Michigan
Directions To 401 East Chestnut Street Louisville Kentucky
Tugboat Information
Pp503063
Craigslist Free Manhattan
Booknet.com Contract Marriage 2
'The Nun II' Ending Explained: Does the Immortal Valak Die This Time?
Babykeilani
How the Color Pink Influences Mood and Emotions: A Psychological Perspective
Samsung 9C8
Terrell Buckley Net Worth
Is Chanel West Coast Pregnant Due Date
Great Clips Virginia Center Commons
Mkvcinemas Movies Free Download
Predator revo radial owners
Obituary Roger Schaefer Update 2020
La Fitness Oxford Valley Class Schedule
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6452

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.