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.

链接地址: http://www.djcxy.com/p/24470.html

上一篇: java.util.zip.ZipEntry中setMethod()的等效Java NIO Zip文件系统

下一篇: 有没有可靠的方法来检测io.js或node.js是否在运行?