How to get node version programmatically?
In this small tutorial, we will learn how to get the version of node programmatically from your Node.js source code.
In Node.js, version of the node can be retrieved using process object. The process object is a global that provides information about, and control over, the current Node.js process.
As a global, it is always available to Node.js applications without using require().
console.log(process.version); // 'v12.11.1'
It can also be explicitly accessed using require()
const process = require('process'); console.log(process.version) //'v12.11.1'
To print Node.js version and the version of all dependencies.
console.log(process.versions);
{ node: '12.1.0', v8: '7.0.276.38-node.18', uv: '1.27.0', zlib: '1.2.11', brotli: '1.0.7', ares: '1.15.0', modules: '67', nghttp2: '1.34.0', napi: '4', llhttp: '1.1.1', openssl: '1.1.1b', cldr: '34.0', icu: '63.1', tz: '2018e', unicode: '11.0' }