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
Verify the installed version with:
nest --version
Step 2: Install npm-check-updates
To update your dependencies, install the npm-check-updates package globally:
npm i -g npm-check-updates
Step 3: Update package.json
Use ncu -u to update your package.json file with the latest dependencies:
ncu -u -f /^@nestjs/
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
Step 6: Install Updated Dependencies
Finally, install the updated dependencies:
npm install
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 (10)
if you want to upgrade only those packages of
@nestjs/
scope, you could use:ncu -u -f /^@nestjs/
Changed the command according to your suggestion. Thanks. 🙏🏻
You right body! thank you for sharing.
Helpful sharing, Thank you
Hello, thank you for this post, it really helps. This command won't trigger updates to
package.json
.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.i am using yarn how do i do that?
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
After upgrading the packages my nest version still showing 9.1.5. can you please suggest what should I do?
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.
here is the screenshot of response message. After following step 1 I was getting the same version 9.1.5 of nest.