How to keep your npm dependencies updated

I'm The Flying Dev - flight attendant and self-taught developer. The founder and host of the Landing in Tech podcast.
Search for a command to run...

I'm The Flying Dev - flight attendant and self-taught developer. The founder and host of the Landing in Tech podcast.
If you use an email long enough, you know how much spam that email will get - some even pass through the filter and reach your inbox. When this happens, you can do three things: Add filtering to delete emails from a specific domain/email address aut...

Actions I've taken to improve security and accounts hardening

When I built the website for Landing in Tech I wanted to have a bar on top of the page with the latest episode. The idea was to allow users to listen to the episode while browsing the page. I added the iframe on my layout.js file and expected it to ...

Version control systems are tools to keep track of changes to source code or other collections of files and folders. They help to track the changes of documents, they make it easy collaborating with someone else. Version Control track changes in a se...

As developers, we use the terminal all the time, it makes sense to learn some shortcuts that can help you do things in the command line. Learning these will also help you boost your productivity because you don't have to retype your commands again j...

It's always a good idea to keep dependencies updated, from performance gains to fixing security issues, it just makes sense to update.
But your project might depend on a lot of dependencies and if you haven't worked on a project for a few months, chances are a lot of these dependencies are really outdated.
You can run the command npm outdated to get a list of all the dependencies that have new releases.

Now that we know how to check for outdated packages, we need to find a way to update them all. This is where we need help from a package called npm-check-updates. This package will look into your package.json versions and upgrade all the outdated ones.
npm install -g npm-check-updates
Note: You should install this package globally so you can use on other projects.
After installing the package you need to run ncu -u on your terminal to upgrade your package.json.

You can now run the command npm update to update your dependencies.
So we have seen that we can upgrade our dependencies with ncu -u and then upgrade them with npm update. How about we create a command that will run both of these so we don't have to type so much?
That's when aliases come in handy!
I keep all my aliases in a .bash_aliases file, in my home directory. You can add this alias anywhere, for example, ~/.bashrc, ~/.zshrc, ~/.bash_profile, etc. If you don't know which to use, you can use ~/.bash_profile or ~/.profile.
Open the file in your favourite editor and add the following alias:
alias update='ncu -u && npm update'
Source that file or restart your terminal and you can now use the update command to update your dependencies in one go!