Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a recommended way to update NestJS?

Tags:

nestjs

I'm currently using 6.0.4, I'd like to get to 6.5.2. What is the best way to do this? Is there something in the CLI? Do I manually update each @nestjs package?

Current dependencies are:

    "@nestjs/common": "^6.0.4",
    "@nestjs/core": "^6.0.4",
    "@nestjs/microservices": "^6.0.4",
    "@nestjs/passport": "^6.1.0",
    "@nestjs/platform-express": "^6.0.4",
    "@nestjs/swagger": "^3.0.2",
like image 338
Robel Robel Lingstuyl Avatar asked Aug 12 '19 23:08

Robel Robel Lingstuyl


People also ask

How to update NestJS version?

First, we install two packages @nestjs/cli and npm-check-updates globally or as so-called devDependency. In this article, we go for the global approach. We need npm-check-updates because the NestJS CLI doesn't cover every single package from NestJS.

What is NEST CLI?

The Nest CLI is a command-line interface tool that helps you to initialize, develop, and maintain your Nest applications. It assists in multiple ways, including scaffolding the project, serving it in development mode, and building and bundling the application for production distribution.

Is NestJS open source?

NestJS is an open-source, extensible, versatile, progressive Node. Js framework for creating compelling and demanding backend systems. It's currently the fastest-growing Node. Js framework in TypeScript.


4 Answers

You can use the Nest CLI to update the dependencies:

$ npm install -g @nestjs/cli
$ nest update

You can also $ nest u

As Mick mentioned in his comment, you might have to add --force argument.

nest update --force

Update - July 7 2022

Since v9.0.0 release, the command update was removed. To upgrade your dependencies, you can use dedicated tools like ncu, npm update, yarn upgrade-interactive, etc.

like image 101
Matt Walterspieler Avatar answered Oct 18 '22 00:10

Matt Walterspieler


Force update with the command:

nest update -f -t latest

nest info 



_   _             _      ___  _____  _____  _     _____
| \ | |           | |    |_  |/  ___|/  __ \| |   |_   _|
|  \| |  ___  ___ | |_     | |\ `--. | /  \/| |     | |
| . ` | / _ \/ __|| __|    | | `--. \| |    | |     | |
| |\  ||  __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/  \____/\_____/\___/


[System Information]
OS Version     : macOS Catalina
NodeJS Version : v12.16.1
NPM Version    : 6.13.4
[Nest Information]
platform-express version : 7.4.2
microservices version    : 7.4.2
common version           : 7.4.2
core version             : 7.4.2

You can check at this post

Nest Docs: nest update

like image 28
Chuong Tran Avatar answered Oct 18 '22 01:10

Chuong Tran


The way I handle this is to manually update each package. It's a little tedious but it gives you full control of what versions each package is set at.

I will usually create a "feature" branch in git, something like feature/upgrade where I'll update the packages

npm i @nestjs/common@latest @nestjs/core@latest ...

Try it out there, then merge that branch into master (or whatever your development branch is). Git removes the need for "copying" code from another directory, if the new package versions breaks something, you have time to fix them in the feature branch before rolling out to production.

like image 6
nerdy beast Avatar answered Oct 18 '22 00:10

nerdy beast


An answer for fast developers:

  1. npx nest update -f
  2. Follow docs.nestjs.com/migration-guide link to apply the changes required for the new version
like image 5
Masih Jahangiri Avatar answered Oct 18 '22 01:10

Masih Jahangiri