Is there a way to get version from package.json in nodejs code?
问题 Is there a way to get the version set in package.json in a nodejs app? I would want something like this var port = process.env.PORT || 3000 app.listen port console.log "Express server listening on port %d in %s mode %s", app.address().port, app.settings.env, app.VERSION 回答1: I found that the following code fragment worked best for me. Since it uses require to load the package.json , it works regardless the current working directory. var pjson = require('./package.json'); console.log(pjson