简体   繁体   中英

Socket.IO Version Output

I upgraded socket.io from 0.9.16 to 1.0.6, and used to output the version like this:

var io = require('socket.io');
console.log("**Socket.IO Version: "+io.version);

and would give me

**Socket.IO Version: 0.9.16

after I updated to 1.0.6, I get:

**Socket.IO Version: undefined

any help? Thanks!

You can do it this way:

console.log("**Socket.IO Version: " + require('socket.io/package').version);

The idea is to load package.json file, which contains information about a Node package.

This is possible because Node's require is able to load JSON modules as well.
From the docs :

If the exact filename is not found, then node will attempt to load the required filename with the added extension of .js , .json , and then .node .

.js files are interpreted as JavaScript text files, and .json files are parsed as JSON text files [...]

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