7

Is it possible to know NODE_MODULE_VERSION in Node.js? If yes, then how? I am interested specifically in the VSCode's builtin Node.js, but maybe Node.js doesn't expose the variable, but VSCode API does?

Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89

1 Answers1

12

To access in node what electron refers to as NODE_MODULE_VERSION, you use:

process.versions.modules


Other values in that object:

> console.log(process.versions)
{
  "http_parser": "2.8.0",
  "node": "8.16.2",
  "v8": "6.2.414.78",
  "uv": "1.23.2",
  "zlib": "1.2.11",
  "ares": "1.10.1-DEV",
  "modules": "57",
  "nghttp2": "1.39.2",
  "napi": "4",
  "openssl": "1.0.2s",
  "icu": "60.1",
  "unicode": "10.0",
  "cldr": "32.0",
  "tz": "2017c"
}
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
  • 1
    Great, I didn't know what is the relation between `NODE_MODULE_VERSION` and `process.versions.modules`. You defined that in the first sentence "what electron refers to as". – Nurbol Alpysbayev Dec 05 '19 at 11:10
  • 1
    FYI- to get this from command line, you can do `node -e "console.log(process.versions)"` – Kip Apr 14 '22 at 18:54
  • 5
    @kip or `node -p "process.versions.modules"` etc – Lawrence Cherone Apr 14 '22 at 19:57
  • 1
    If I need the nodejs `NODE_MODULE_VERSION` to match the electron `NODE_MODULE_VERSION` (the same module needs to be shared used by both electron and nodejs modules) can I assume I need the node.js version to match the electron version? – Michael Nov 07 '22 at 00:17