You can lock your application with a specific node.js version. This will help you to isolate the dependencies of of your node.js application. So you can quickly install required packages on any system.

In this tutorial, you will learn a simple process of specifying node.js version using .nvmrc file.

Using .nvmrc

Create a .nvmrc file containing a node version number in your project. You can use the nvm —-help to check other options. After that you can simply run commands like nvm use, nvm install and nvm run etc. This will the default node.js version defined in .nvmrc file.

For example, to make nvm default to use 12.10, or the latest LTS version, or the latest available node version. Use once of the below commands.

  1. Use specific node version, like: 12.10
    echo "12.10" > .nvmrc 
  2. Set latest LTS node version as default
    echo "lts/*" > .nvmrc 
  3. Set latest node version as default
    echo "node" > .nvmrc 

After setting the default node version, use nvm use command to set default node version found in .nvmrc. Similarly if specified node version is not installed simply run nvm install.

nvm use
nvm install

The above commands will traverse directory structure upwards from the current directory looking for the .nvmrc file. In other words, once you set the node version with .nvmrc, can run nvm commands from any sub directory of the application.

The post Using .nvmrc to Specify Node Version appeared first on TecAdmin.