6

I have a node js project running in node v6.12.0 and I need to update the project to node v12.18.

These are some of the dependencies tagged to the project in package.json:

{
  "hapi": "^8.8.0"
  "joi": "^6.4.1"
  "mocha": "^2.4.5"
  "ioredis": "^2.4.0"
}

Wondering what all steps should I do for making this upgrade possible!

Will there be a break in code functionalities if I upgrade to node v12? Is it backward compatible to node v6? Does all those Promise.then(function()) still would work in node v12?

joncloud
  • 757
  • 5
  • 14
LGAP
  • 2,365
  • 17
  • 50
  • 71
  • 2
    I would install node v12, run the application and see what errors you get (if any). – Felix Kling Nov 03 '20 at 08:56
  • 1
    I usually create a docker container with the node image I want and run my application in it to solve my issues. For simplicity, you can use nvm to manage different versions of node and simply switch between them as needed. – nishkaush Nov 03 '20 at 09:00

1 Answers1

21

The current latest+stable version of node is 14.x. So I would suggest you use node v14. But ultimately it's your choice as to which version you want to use. You can use nvm to manage multiple node versions & it can be downloaded from here - https://github.com/nvm-sh/nvm.

Two simple commands to keep in mind for nvm are

  1. nvm ls - Prints the node versions installed on your machine & the current node version you're using.
  2. nvm use 14.x - Switch between node versions which you want. Here after running this command, I'll be using node v14.x

This is how you use the new node versions.

Now, in order to update the npm package.json dependencies, please use this awesome package called ncu https://www.npmjs.com/package/npm-check-updates.

Once you run ncu command in your project folder, ncu will analyze all the dependencies in your package.json & suggest the possible upgrades for your package.json

There is another amazing command - ncu --doctor -u - This will iteratively install upgrades and run your unit tests to identify any breaking upgrades. And if it finds any breaking changes after upgrading a certain dependency, it will revert back to the previous version to prevent the breakage.

Amey Lokhande
  • 402
  • 5
  • 11
  • 3
    The `ncu --enginesNode` command is also helpful, given that the dependencies use the `engines.node` field in package.json. For reference, the flag's description: "Include only packages that satisfy engines.node as specified in the package file." – joncloud Jul 10 '21 at 03:40