Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find what node version a project supports

Tags:

node.js

npm

nvm

Is there a way besides trial and error to detect what node version I should use on a repository ?

With the fast rise of web frameworks it's becoming a common need to go back to projects from 6, 12 or 24+ months ago. I've been doing this a lot in the last weeks and my process for detecting the correct node version has become:

git clone [REPO]
npm i
[build]
### if error
rm -r node_modules
nvm use 4, 5 or 6
npm i
[build]

I can't help but feel that there's something very basic I'm missing here. Thanks for any wisdom you can share with me!

like image 806
coiso Avatar asked Mar 15 '17 09:03

coiso


2 Answers

As mentioned in other answers, some packages have an engines field in the package.json. npm will warn users if they try to install a package on a Node.js version not supported by the package. The engines field looks like this:

{
  "engines": {
    "node": ">=4.0.0"
  }
}

More info: https://docs.npmjs.com/files/package.json#engines


Also, many packages have a CI, like TravisCI, set up to automatically test packages. These CI config files often contain a list of Node.js versions to test on. Generally, the lowest version number in the CI config is the minimum version supported by the package.

Common config file names are .travis.yml, appveyor.yml, circle.yml, etc.

Example:

.travis.yml:

language: node_js
node_js:
  - "4"
  - "5"
  - "6"
  - "7"

This config means that the package probably supports Node.js v4+

like image 126
RyanZim Avatar answered Oct 13 '22 23:10

RyanZim


If these are your own repos, then you can store the Node version in package json for your reference.

"version": "1.0.0",
"engines": {
    "node": "7.x"
},
"description": "..."

This won't automatically setup the correct version, but it would provide you with somewhere to look.

like image 24
Varedis Avatar answered Oct 13 '22 23:10

Varedis