Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript print node.js version and modules versions

running a node.js server and I want to display in my javascript code the nodejs version and all it's module and versions. something like
console.log(MODULENAME.version), .. don't know how to do that and its syntaxe . Any help appreciated

like image 227
user2606148 Avatar asked Nov 16 '25 17:11

user2606148


1 Answers

You can get this from your package.json:

const packageDetails = require('./package.json');

console.log('Platform: ', process.platform);
console.log('Node version: ', process.version);
console.log('Node dependencies: ', process.versions);
console.log('Server version: ', packageDetails.version);
let keys = Object.keys(packageDetails.dependencies);
console.log('Modules: ');
keys.forEach((k) => {
    console.log(`${k}: ${packageDetails.dependencies[k]}`);
})
like image 97
Terry Lennox Avatar answered Nov 18 '25 08:11

Terry Lennox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!