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
Elon Musk, Bitcoin and the Rise of Cryptocurrencies | TC Global
June Blog Traffic & Income Report - Living on Fifty
Drury Inn & Suites Bowling Green
Sound Of Freedom Showtimes Near Governor's Crossing Stadium 14
Regal Amc Near Me
Missing 2023 Showtimes Near Cinemark West Springfield 15 And Xd
Exam With A Social Studies Section Crossword
Fully Enclosed IP20 Interface Modules To Ensure Safety In Industrial Environment
Linkvertise Bypass 2023
Noaa Swell Forecast
How to Type German letters ä, ö, ü and the ß on your Keyboard
T&G Pallet Liquidation
Garrick Joker'' Hastings Sentenced
Tamilblasters 2023
Clairememory Scam
Jasmine Put A Ring On It Age
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
3476405416
Rural King Credit Card Minimum Credit Score
Azpeople View Paycheck/W2
Jenna Ortega’s Height, Age, Net Worth & Biography
Football - 2024/2025 Women’s Super League: Preview, schedule and how to watch
Www.paystubportal.com/7-11 Login
Bòlèt Florida Midi 30
Stihl Dealer Albuquerque
Haunted Mansion Showtimes Near Epic Theatres Of West Volusia
Arrest Gif
Spectrum Outage in Queens, New York
They Cloned Tyrone Showtimes Near Showbiz Cinemas - Kingwood
Airg Com Chat
Wheeling Matinee Results
Warn Notice Va
Eaccess Kankakee
Forager How-to Get Archaeology Items - Dino Egg, Anchor, Fossil, Frozen Relic, Frozen Squid, Kapala, Lava Eel, and More!
Tamil Play.com
Pickle Juiced 1234
Kips Sunshine Kwik Lube
T&J Agnes Theaters
Today's Final Jeopardy Clue
Gold Nugget at the Golden Nugget
Babylon 2022 Showtimes Near Cinemark Downey And Xd
Babbychula
Nancy Pazelt Obituary
The TBM 930 Is Another Daher Masterpiece
Easy Pigs in a Blanket Recipe - Emmandi's Kitchen
Oppenheimer Showtimes Near B&B Theatres Liberty Cinema 12
Sand Castle Parents Guide
Zipformsonline Plus Login
Best Restaurant In Glendale Az
300+ Unique Hair Salon Names 2024
Minecraft: Piglin Trade List (What Can You Get & How)
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.