How can I check Nodejs version by using code Javascript?

Dung Do Tien Sep 25 2021 5

Hello Guys.

I am a beginner Nodejs and I learn and code Nodejs by using editor from website online. Now I want to check version of current node but I can not run node -v command because editor not support.

How can I check nodejs version by using code?

Thanks for any suggestions.

Have 2 answer(s) found.
  • S

    Steve Mart Sep 25 2021

    You can use process variable global on Nodejs to check version of Nodejs:

     console.log(process.version); // 'v12.22.6'

    It can also be explicitly accessed using require()

     const process = require('process');
    
    console.log(process.version) //'v12.22.6'

    It's worked well for me.

  • M

    Mobile Legend Sep 25 2021

    To print Node.js version and the version of all dependencies you can try command below:

     console.log(process.versions);

    #Output

     {
      node: '12.22.6',
      v8: '7.8.279.23-node.56',
      uv: '1.40.0',
      zlib: '1.2.11',
      brotli: '1.0.9',
      ares: '1.17.2',
      modules: '72',
      nghttp2: '1.41.0',
      napi: '8',
      llhttp: '2.1.3',
      http_parser: '2.9.4',
      openssl: '1.1.1l',
      cldr: '37.0',
      icu: '67.1',
      tz: '2019c',
      unicode: '13.0'
    } 
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close