How do I get the minimum version of node.js in my script?

I just found out that the script only wrote work on node 0.10 because it uses readable events.

How do I require a minimal version of node.js in my script so that users know what they need to update?

+6
source share
2 answers

In package.json:

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

From docs .

Change, software way:

 var pkg = require('./pacakge'), semver = require('semver'); if(!semver.satisfies(process.version, pkg.engines.node)) { // Not sure if throw or process.exit is best. throw new Error('Requires a node version matching ' + pkg.engines.node); } 
+12
source

Add this at the top of the script page.

 var versionComps = process.versions['node'].split('.'); if (parseInt(versionComps[0]) === 0 && parseInt(versionComps[1]) < 10) { console.log('Script requires node.js version >= 0.10'); process.exit(1); }; 
+1
source

Source: https://habr.com/ru/post/953614/


All Articles