Search code examples
node.jspromisehapi

Updating node version of a project from v6x to v12x


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?


Solution

  • 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.