Ciprian Craciun - FrontEnd Developer

Ciprian Craciun

FrontEnd/Web Developer

Engineering is about making a product better, learning from past mistakes and create a process which is easy for all to understand.

How to manage your package JSON file with npm

Stay ahead of the game with npm package updates! Discover the simplest way to keep your package JSON file up-to-date and leverage the latest advancements in front-end development. Boost your project’s performance, stay current with cutting-edge technologies, and safeguard against security risks. Let’s dive into the world of hassle-free package updates using npm.

The best approach for a front-end project is always to have the latest packages updated. Why? You are up to date with the latest technologies and also you can prevent problems related to security.

Use npm Outdated: Streamline Package Updates for Enhanced Performance

By running the “npm outdated” command in your project’s root directory, you can quickly assess the number of npm packages that are in need of updates. This command provides a comprehensive overview of the outdated packages specified in your package JSON file. Stay informed about the latest updates available for your dependencies and ensure your project remains up-to-date with the most recent package versions.

npm outdated
npm outdated

Run npm update

Running npm update will auto-update packages without the need to update them manually.

Before running npm update if you have some packages that don’t need updates or maybe it’s a package with some deprecations, no longer maintained by the author, you can change the version of the package to be fixed like this: “next”: “^10.2.3” → “next”: “10.2.3”.

Removing the “^” from the package version, we set a fixed version and when we run npm update that package will not be updated to the next version.

Scan your project for vulnerabilities with the npm audit

Yes, we can audit our packages running npm audit, this will tell you if you have any vulnerabilities and what to do to fix them.

Npm audit report
npm audit example report

Read carefully all the pieces of information from the report, some suggestions may not be a fit for your project.

The last command you should run after the report review is npm audit fix, this will automatically update all the broken packages. Other options for npm audit can be found on the official docs.

From my point of view, this would be a good behavior to have as a Developer, check your packages because when you code new features it’s easy just to add packages without checking for vulnerabilities.

If you like what I suggested here you can follow me on Twitter or subscribe to my newsletter.

Sharing is caring!


Leave a Reply

Your email address will not be published. Required fields are marked *