33

How to update Nest.js (2022)

 2 years ago
source link: https://blog.bitsrc.io/how-to-update-nest-js-ecd0e9466165
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to update Nest.js (2022)

In this article, I want to talk about Nest.js and how you update it with two packages you need to have installed.

Code
Photo by James Harrison on Unsplash

What is Nest.js?

Nest.js is a framework for building efficient, scalable Node.js web applications. It uses modern JavaScript, is built with TypeScript, and combines elements of OOP (Object Oriented Programming) and Dependency Injection. If you develop an API based on Node.js, then Nest.js is the way to go since 2018.

How to update Nest.js?

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 Nest.js CLI doesn’t cover every single package from Nest.js.

$ npm install -g @nestjs/cli npm-check-updates

Now we can update Nest.js with the Nest.js CLI.

$ nest update
$ nest update --force

The force flag basically removes your official Nest.js packages from our package.json and node_modules to reinstall them on the most latest version. Since I didn’t update Nest.js in my project for a while, my Git changes look like this:

Dependencies of my project
Dependencies of my project

But we are not done yet. As I said, the Nest.js CLI doesn’t cover everything. So we can run two additional commands with the npm-check-updates package.

$ npm-check-updates "/@nestjs*/" -u

The command above updates other official Nest.js packages which are not covered by the nest update command.

My console output looks like this:

Upgrading package.json
[====================] 17/17 100%@nestjs/cli ^8.1.6 → ^8.2.1
@nestjs/schematics ^8.0.5 → ^8.0.6
@nestjs/testing ^8.2.4 → ^8.3.1Run npm install to install new versions.

Great, right? Now we updated all official Nest.js packages. But yet, we are still not done. First of all, we can see, that we have to run npm install to install the updates, but we also want to update the unofficial Nest.js packages from other developers we might use. So what I gonna do next is this command.

$ npm-check-updates "/nestjs*/" -u

My console output looks like this:

Upgrading package.json
[====================] 17/17 100%@ntegral/nestjs-sentry ^3.0.6 → ^3.0.7Run npm install to install new versions.

Now I have updated one unofficial Nest.js package as well. To install all updates we have made with the npm-check-updates package, we need to run one last command:

$ npm install

What’s next?

After updating dependencies it’s always very important to test your code before you go into production.

Thanks for reading my article about how to update Nest.js. I hope, you could get something out of this article.

Cheers!


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK