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

柔情痞子 提交于 2019-12-10 03:52:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28259154/is-there-a-reliable-way-of-detecting-whether-io-js-or-node-js-is-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!