Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How do I require a minimum version of node.js in my script?

How do I require a minimum version of node.js in my script?

Problem

I just found out that a Script I wrote only works on node 0.10 because it uses readable events.

How do I Require a minimum version of node.js in my script so that users know that they need to upgrade?

Problem courtesy of: hwiechers

Solution

In package.json:

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

From the docs.

Edit, a programmatic 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);
}
Solution courtesy of: Andreas Hultgren

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How do I require a minimum version of node.js in my script?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×