7

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?

nitishagar
  • 9,038
  • 3
  • 28
  • 40
Chris
  • 4,594
  • 4
  • 29
  • 39
  • I've just found this question but a few days ago I asked something similar but [detecting between nodejs, iojs, jxcore, and the Microsoft fork of node with the ChakraCore js engine](http://stackoverflow.com/questions/35037072). – hippietrail Feb 01 '16 at 10:04

1 Answers1

3

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.

alexpods
  • 47,475
  • 10
  • 100
  • 94
  • The first solution would fail if `node` wasn't pointing to the current executable(ie two iojs and node being installed side by side...) – Farid Nouri Neshat Feb 01 '15 at 13:58
  • 1
    @FaridNouriNeshat For now `node` and `iojs` cannot be installed "side by side". Also problem you described can be fixed using `process.execPath`. So I updated the answer. Thanks for remark. – alexpods Feb 01 '15 at 14:00
  • They can be as long as they are installed in different places, but yeah, process.execPath is solution for it. :D – Farid Nouri Neshat Feb 02 '15 at 05:00