DEV Community

Cover image for How to Upgrade NestJS 9 to 10: A Developer's Guide
amir fakoor
amir fakoor

Posted on

How to Upgrade NestJS 9 to 10: A Developer's Guide

In this tutorial, we will walk through the process of upgrading a NestJS application from version 9 to 10. This guide is intended for developers who have an existing NestJS project and wish to update it to the latest version.

Step 1: Update the NestJS CLI
First, update the NestJS CLI to the latest version by running the following command:

npm install -g @nestjs/cli
Enter fullscreen mode Exit fullscreen mode

Verify the installed version with:

nest --version
Enter fullscreen mode Exit fullscreen mode

Step 2: Install npm-check-updates
To update your dependencies, install the npm-check-updates package globally:

npm i -g npm-check-updates
Enter fullscreen mode Exit fullscreen mode

Step 3: Update package.json
Use ncu -u to update your package.json file with the latest dependencies:

ncu -u -f /^@nestjs/
Enter fullscreen mode Exit fullscreen mode

Image description

Step 4: Verify Changes
Review the changes in your package.json file, ensuring that the NestJS dependencies are updated to the desired version (v10).

Step 5: Remove package-lock.json and node_modules
Delete the package-lock.json file and the node_modules folder with the following commands:

rm package-lock.json
rm -rf node_modules
Enter fullscreen mode Exit fullscreen mode

Step 6: Install Updated Dependencies
Finally, install the updated dependencies:

npm install
Enter fullscreen mode Exit fullscreen mode

Conclusion
After completing these steps, your NestJS application should be updated to version 10. Be sure to test your application thoroughly to ensure that there are no issues or breaking changes caused by the upgrade. Happy coding!

Top comments (9)

Collapse
 
micalevisk profile image
Micael Levi L. C.

if you want to upgrade only those packages of @nestjs/ scope, you could use:

ncu -u -f /^@nestjs/

Collapse
 
amirfakour profile image
amir fakoor

You right body! thank you for sharing.

Collapse
 
amirfakour profile image
amir fakoor

Changed the command according to your suggestion. Thanks. 🙏🏻

Collapse
 
amangeot profile image
Adrien Mangeot • Edited

Hello, thank you for this post, it really helps. This command won't trigger updates to package.json.

$ ncu -u -f /^@nestjs/
Upgrading C:\Users...\package.json
No dependencies.

NestJS v10.3.1 is now available and dependency in package.json points to @nestjs/common": "^9.2.1.

Is there anything to do beforehand?

Running ncu -u @nestjs/* seems to do the job though.

Collapse
 
mmsohan profile image
MD. Masbahul

After upgrading the packages my nest version still showing 9.1.5. can you please suggest what should I do?

Collapse
 
amirfakour profile image
amir fakoor

capture a screenshot of the command outcome by executing ncu -u -f /^@nestjs/ Please share the screenshot as a response to this message. Ensure that the screenshot resembles the image provided in the tutorial.

Also, remember to follow step 1 and update your CLI.

Collapse
 
mmsohan profile image
MD. Masbahul

Image description
here is the screenshot of response message. After following step 1 I was getting the same version 9.1.5 of nest.

Collapse
 
arsh028 profile image
Arsh Radhanpura

i am using yarn how do i do that?

Collapse
 
amirfakour profile image
amir fakoor

Instead of step 2, use the following command:
yarn global add yarn-upgrade-all
After that, execute:
yarn-upgrade-all --ignore "^((?!@nestjs).)*$" --upgrade
Finally, run this command:
yarn install