Node.js version on the command line? (not the REPL)
Asked Answered
C

10

717

I want to get the version of Node.js on the command line. I'm expecting to run a command like:

node -version

but that doesn't work. Does anybody know what the command line would be? (i.e. not the REPL)

Conative answered 15/2, 2013 at 4:54 Comment(4)
Yes, the runtime question works for the Node command line, not the shell. Of course, "command line" could refer to either thing.Rosenquist
Check node --help. But, in short, you need 2 dashes for full-name options: node --version. A single dash starts a group of aliases, so -version combines -v, -e, -r, etc -- though only 3 of the 7 are recognized by Node.Ministry
@JonathanLonowski: Good to know about node --help (node -h works too). However, node does not support grouping of options the way you describe; e.g., node -p -i works (syntactically - as of 0.12, no combination of short options makes sense semantically), but node -pi results in an unrecognized flag / bad option (0.12) error.Sardonic
This may help somebody!Illegalize
L
1233

The command line for that is:

node -v

Or

node --version

Note:

If node -v doesn't work, but nodejs -v does, then something's not set up quite right on your system. See this other question for ways to fix it.

Lacerated answered 15/2, 2013 at 4:58 Comment(4)
In the year 2015, this no longer works. Use nodejs -v instead.Brooklime
@AndrewThaddeusMartin node -v does work. I'm using latest version available today which is 0.12.6.Lithosphere
This works in 6.8.0: >node -v v6.8.0 >node --version v6.8.0Erective
node -v => v8.11.2 => So this works also for v8.11.2Attila
R
87

If you're referring to the shell command line, either of the following will work:

node -v

node --version

Just typing node version will cause node.js to attempt loading a module named version, which doesn't exist unless you like working with confusing module names.

Rosenquist answered 15/2, 2013 at 5:3 Comment(1)
You're welcome. Note, however, that the OP typed node -version, not node version. The former reports an unrecognized flag / bad option (in 0.12) error and then enters the REPL, whereas the latter indeed tries to load a non-existent file, and aborts without entering the REPL. @JonathanLonowski has already stated it in a comment on the question, but let me repeat it here: node -h or node --help shows all supported command-line options.Sardonic
T
41

Try nodejs instead of just node

$ nodejs -v
v0.10.25
Tense answered 29/10, 2014 at 2:52 Comment(1)
Note: The node.js executable (binary) should be node, not nodejs. However, there was a naming conflict on some Linux distros (e.g., Ubuntu), resulting in the executable getting installed as nodejs. As of Ubuntu 14.04, for instance, apt-get install nodejs will also install executable node (implemented as a symlink to nodejs). In other words: For consistency, try node -v first.Sardonic
V
33

Just type npm version in your command line and it will display all the version details about node, npm, v8 engine etc.

enter image description here

Vernellvernen answered 16/2, 2019 at 11:29 Comment(0)
S
16

Repl Command to find the Nodejs Version

$node
>process.version
`v8.x`
Shithead answered 3/10, 2017 at 5:14 Comment(1)
The question title literally says "NOT THE REPL"Polash
C
15

Node:

node --version or node -v

npm:

npm --version or npm -v

V8 engine version:

node -p process.versions.v8
Camlet answered 7/5, 2016 at 14:54 Comment(0)
W
11

find the installed node version.

$ node --version

or

 $ node -v

And if you want more information about installed node(i.e. node version,v8 version,platform,env variables info etc.)

then just do this.

$ node
> process
  process {
  title: 'node',
  version: 'v6.6.0',
  moduleLoadList: 
   [ 'Binding contextify',
     'Binding natives',
     'NativeModule events',
     'NativeModule util',
     'Binding uv',
     'NativeModule buffer',
     'Binding buffer',
     'Binding util',
     ...

where The process object is a global that provides information about, and control over, the current Node.js process.

Wagshul answered 30/9, 2016 at 11:6 Comment(1)
>process.version will only show the version and not the full process objectNeeds
M
5

By default node package is nodejs, so use

$ nodejs -v

or

$ nodejs --version 

You can make a link using

$ sudo ln -s /usr/bin/nodejs /usr/bin/node

then u can use

$ node --version

or

$ node -v
Meteorology answered 2/2, 2016 at 18:48 Comment(1)
This naming inconsistency in some distros was already noted in a 2014 answer. stackoverflow.com/a/26622019Polash
Q
5

One cool tip if you are using the Atom editor.

$ apm -v
apm  1.12.5
npm  3.10.5
node 4.4.5
python 2.7.12
git 2.7.4

It will return you not only the node version but also few other things.

Quintinquintina answered 25/10, 2016 at 18:24 Comment(1)
apm -v will tell you the version of node and npm that Atom is using. It may not necessarily be the one that will be if you are using the command lineChervonets
T
2

On November 2023 this command is working perfect:

node -v

Note date and time at the command prompt

Note date and time at the command prompt on this screen capture. So there's no ambiguity on node or nodejs. It seems it has been standardized long ago and it still works as shown here.

Node has some kind of an issue with its dependent frameworks and utilities and version management has been a must for me since it gained popularity. I often needed to review old code that didn't run on the version I was using at present time.

The solution was node version manager "nvm" you can install from github: https://github.com/nvm-sh/nvm this tool will inform you of your node version and will allow you to change it temporarily or as often as you need.

Touraco answered 18/11, 2023 at 10:2 Comment(6)
Please don't duplicate existing answers, unless you want to share new insights. If this is the case here, please add some more explanation to your answer such that others can learn from itCalysta
Nico, this is not the same answer. There are two main differences: 1. is a confirmation on that on 2023 november, the command is still working (not nodejs -v) 2. Proposal of nvm as a version manager. Or is it that you need more badges or reputation points??Touraco
Please add all clarification to your answer by editing it. And no, I don't gain any badge or reputation pointCalysta
That node -v is working was already written in https://mcmap.net/q/47968/-node-js-version-on-the-command-line-not-the-repl seven years ago. Posting that information again does not provide any additional benefit. And how does nvm relate to the given question?Calysta
Still on the same? It doesn't provide any information that you can still use the same command seven years later? (some answers suggested there was a variation along time). And NVM is a wonderful tool to, not only get the current version, but manage what has been a long time node issue: some of their dependent utilities are version linked. And the question itself is about versioning, so why should NVM not be relevant.?Touraco
I was following someone's answers and finished here. I just tried to add my grain, but I'm at one step to delete it all. Writing at SO has become a time wasting experience, it doesn't make sense anymore.Touraco

© 2022 - 2024 — McMap. All rights reserved.