{

How to update nestjs application to the latest with examples


This tutorial explains about following things

  • Update nestjs cli to the latest version
  • Upgrade nest project dependencies to the latest

How to update NestJS cli upgrade

NestJS CLI is a command line interface to create an application, and generate components.

You can either install it freshly or use the update command to upgrade next version.

My Current nestjs version is

nest --version
9.1.4

Let’s see how to update(upgrade) NestJS Cli to the latest version

npm install -g @nestjs/cli

or
npm install -g @nestjs/[email protected]

Once installed the latest version, You can check the version using the below command.

nest --version
9.1.5

How to update the nestjs application to the latest version

NestJS application following dependencies

  • Nestjs dependencies(@nestjs/common,@nestjs/core etc.. )
  • Application dependencies(eslint,passport,TypeOrm etc)

We need to upgrade the above two types of dependencies to the latest to upgrade the entire application.

To update NestjS application to latest version

  • First, Check and print the current application and the latest version of dependencies of an application using the below command (npm outdated)
A:\work\nestjs\nestjs-hello-world>npm outdated
Package                           Current   Wanted   Latest  Location                                       Depended by
@nestjs/cli                         9.1.4    9.1.5    9.1.5  node_modules/@nestjs/cli                       nestjs-hello-world
@nestjs/common                      9.1.6    9.2.0    9.2.0  node_modules/@nestjs/common                    nestjs-hello-world
@nestjs/core                        9.1.6    9.2.0    9.2.0  node_modules/@nestjs/core                      nestjs-hello-world
@nestjs/platform-express            9.1.6    9.2.0    9.2.0  node_modules/@nestjs/platform-express          nestjs-hello-world
@nestjs/testing                     9.1.6    9.2.0    9.2.0  node_modules/@nestjs/testing                   nestjs-hello-world
@types/jest                        28.1.8   28.1.8   29.2.3  node_modules/@types/jest                       nestjs-hello-world
@types/node                       16.18.0  16.18.3  18.11.9  node_modules/@types/node                       nestjs-hello-world
@typescript-eslint/eslint-plugin   5.41.0   5.44.0   5.44.0  node_modules/@typescript-eslint/eslint-plugin  nestjs-hello-world
@typescript-eslint/parser          5.41.0   5.44.0   5.44.0  node_modules/@typescript-eslint/parser         nestjs-hello-world
eslint                             8.26.0   8.28.0   8.28.0  node_modules/eslint                            nestjs-hello-world
jest                               28.1.3   28.1.3   29.3.1  node_modules/jest                              nestjs-hello-world
prettier                            2.7.1    2.8.0    2.8.0  node_modules/prettier                          nestjs-hello-world
ts-jest                            28.0.8   28.0.8   29.0.3  node_modules/ts-jest                           nestjs-hello-world
typescript                          4.8.4    4.9.3    4.9.3  node_modules/typescript                        nestjs-hello-world

The above list contains all the dependencies with the current, latest version.

And the current package.json contains the following entries

"dependencies": {
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/platform-express": "^9.0.0",
    "nestjs-real-ip": "^2.2.0",
    "reflect-metadata": "^0.1.13",
    "request-ip": "^3.3.0",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "28.1.8",
    "@types/node": "^16.0.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "28.1.3",
    "prettier": "^2.3.2",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "28.0.8",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.7.4"
  },
  • Next, Install the npm-check-updates package globally using the below command

npm-check-updates provides ncu tool to update package.json by replacing the current version with the latest json.

npm i -g npm-check-updates
  • Now, ncu command is ready to run,
  • Run ncu -u command

It updates package.json with all the latest versions.

A:\work\nestjs\nestjs-hello-world>ncu -u
Upgrading A:\work\nestjs\nestjs-hello-world\package.json
[====================] 29/29 100%

 @nestjs/cli                         ^9.0.0  →    ^9.1.5
 @nestjs/common                      ^9.0.0  →    ^9.2.0
 @nestjs/core                        ^9.0.0  →    ^9.2.0
 @nestjs/platform-express            ^9.0.0  →    ^9.2.0
 @nestjs/schematics                  ^9.0.0  →    ^9.0.3
 @nestjs/testing                     ^9.0.0  →    ^9.2.0
 @types/express                    ^4.17.13  →  ^4.17.14
 @types/jest                         28.1.8  →    29.2.3
 @types/node                        ^16.0.0  →  ^18.11.9
 @types/supertest                   ^2.0.11  →   ^2.0.12
 @typescript-eslint/eslint-plugin    ^5.0.0  →   ^5.44.0
 @typescript-eslint/parser           ^5.0.0  →   ^5.44.0
 eslint                              ^8.0.1  →   ^8.28.0
 eslint-config-prettier              ^8.3.0  →    ^8.5.0
 eslint-plugin-prettier              ^4.0.0  →    ^4.2.1
 jest                                28.1.3  →    29.3.1
 prettier                            ^2.3.2  →    ^2.8.0
 rxjs                                ^7.2.0  →    ^7.5.7
 source-map-support                 ^0.5.20  →   ^0.5.21
 supertest                           ^6.1.3  →    ^6.3.1
 ts-jest                             28.0.8  →    29.0.3
 ts-loader                           ^9.2.3  →    ^9.4.1
 ts-node                            ^10.0.0  →   ^10.9.1
 typescript                          ^4.7.4  →    ^4.9.3

Run npm install to install new versions.

package.json contains with all the latest version

{
  "dependencies": {
    "@nestjs/common": "^9.2.0",
    "@nestjs/core": "^9.2.0",
    "@nestjs/platform-express": "^9.2.0",
    "nestjs-real-ip": "^2.2.0",
    "reflect-metadata": "^0.1.13",
    "request-ip": "^3.3.0",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.7"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.1.5",
    "@nestjs/schematics": "^9.0.3",
    "@nestjs/testing": "^9.2.0",
    "@types/express": "^4.17.14",
    "@types/jest": "29.2.3",
    "@types/node": "^18.11.9",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.44.0",
    "@typescript-eslint/parser": "^5.44.0",
    "eslint": "^8.28.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-prettier": "^4.2.1",
    "jest": "29.3.1",
    "prettier": "^2.8.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.1",
    "ts-jest": "29.0.3",
    "ts-loader": "^9.4.1",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.9.3"
  }
  }
  • Next, remove package-lock.json and delete node_modules folder
  • Run thenpm install command to install the latest versions
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.