12

I do a lot of browsing on GitHub and find neat little Node projects that I like to play around with. The only problem is, most come with hardly any documentation. For starters, which version of Node I need to be using in order to run the project/application. I use nvm so I can easily swap between versions, but not knowing what version I need is a little frustrating.

Is there a specific way, possibly by examining the source code, to tell which version of Node I need to use in order to install/run an application?

3
  • Have you had issues with incompatible versions? Usually if you run it by yourself, this should not be an issue. nvm is to ensure that the same node version is used across multiple platforms, e.g. when developing in a team. Other than that I guess the packages package.json knows the dependencies and install whats needed Commented Sep 24, 2018 at 22:38
  • Nodejs uses JavaScript, installing latest version of nodejs should be compatible with any projects. Unless if the projects use some outdated or depricated modules. Commented Sep 24, 2018 at 22:39
  • A part of my team recently inherited a bunch of old apps that apparently weren't upgraded for a long time and also need different versions of nodes. When we opened a project first time, we encountered module errors. We had to google errors, and links finally will ended up taking us on gitbub and there we find out why a given module is failing, and what version of node does that app need. Commented Mar 13, 2020 at 13:48

2 Answers 2

7

In your package.json, use engines

Example:

{ "engines": { "node": ">=0.10.3 <0.12" } } 

It don't auto install Node.js version, but it will alert wrong version or developer can see version necessary.

Sign up to request clarification or add additional context in comments.

1 Comment

Not everyone uses engines, so if you download an app from github, or when you inherit a project in your team, it does take time to find out what @amy is asking.
3

Use npm install --dry-run which should tell you whether or not your current engine is supported.

In some cases, it picks a package that is dependent on a specific engine and displays a useful warning that tells you which version to use. E.g.

╰─ npm i --dry-run ─╯ npm WARN old lockfile npm WARN old lockfile The package-lock.json file was created with an old version of npm, npm WARN old lockfile so supplemental metadata must be fetched from the registry. npm WARN old lockfile npm WARN old lockfile This is a one-time fix-up, please be patient... npm WARN old lockfile npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '[email protected]', npm WARN EBADENGINE required: { node: '>=6.0.0 <13.0.0', npm: '>=3.0.0' }, npm WARN EBADENGINE current: { node: 'v14.17.1', npm: '8.1.3' } npm WARN EBADENGINE } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.