简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM