Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reliable way of detecting whether io.js or node.js is running?

Tags:

node.js

io.js

The only way I can kind-of infer whether node.js or io.js is running is to check process.versions.node. In io.js, I get 1.0.4.

I'm sure there's a better way - anyone know?

like image 314
khoomeister Avatar asked Feb 01 '15 03:02

khoomeister


1 Answers

Now the most reliable solution is to exec node -h and see if it contains iojs.org substring. If it does - it's iojs:

function isIojs(callback) {
    require('child_process').exec(process.execPath + ' -h', function(err, help) {
        return err ? callback(err) : callback(null, /iojs\.org/.test(help));
    });
}

The big minus of such approach - it's asynchronous. So I wrote a small library which is simplifying the job: is-iojs.

But frankly speaking: who knows when node version 1 will be released, maybe never. So I think for now determination based only on process.version is enough:

var isIojs = parseInt(process.version.match(/^v(\d+)\./)[1]) >= 1;

Also you can check process.execPath string, but this approach does not works for windows as far as I know.

like image 101
alexpods Avatar answered Sep 20 '22 00:09

alexpods