When you install Node, you also get npm, which is the official package manager for Node.
You can use npm to install dependencies that other people wrote for you to use in your project.
Over time, these dependencies get updates and you'll want to update them so keep up with the latest versions.
In this post, we'll learn how to update our dependencies with npm.
Check for outdated dependencies
Before we update our dependencies, we need to check if there are any outdated dependencies.
You can do this by running this command:
BASHnpm outdated
This command will list all the dependencies that are outdated. Simply run it in the root of your project, the same place where your package.json file is located.
Now that we know how to check for outdated dependencies, let's update our dependencies.
Updating outdated dependencies
You can update a specific dependency by running this command:
BASHnpm update <dependency>
For example, if you wanted to update the react dependency, you would run this command:
BASHnpm update react
If your package is installed globally, you will need to apply the --global flag to it:
BASHnpm update --global react
When you run any of these commands, npm will automatically update the dependency, package.json and your node_modules folder.
You can update all the dependencies at once by running this command:
BASHnpm update
By omitting the <dependency> argument, npm interprets it as you wanting to update all the dependencies.
Finally, you can choose what version specifically you want to update a dependency to by appending the version to it.
For example, here's how to update react to the latest version:
BASHnpm update react@latest
Conclusion
In this post, we learned how to update our dependencies with npm.
You can first verify which packages are outdated, then update them one by one, or all at once.
Hopefully this post has been helpful to you. Thanks for reading!
Getting Started with Solid
How to Serve Static Files with Nginx and Docker
How to Set Up Cron Jobs in Linux
How to deploy a .NET app using Docker
Best Visual Studio Code Extensions for 2022
How to deploy a Deno app using Docker
Getting Started with Deno
How to deploy a Node app using Docker
Learn how to use v-model with a custom Vue component
How to Scrape the Web using Node.js and Puppeteer
Getting Started with Moment.js
Getting Started with React
