How Can I Tell if node.js is Properly Installed?

When I run node -v in my terminal I get a response showing V22.12.0 is installed. When I try to run sample or ‘try it’ code, nothing happens and the command prompt does not return unless I do a ctl-break. The code snippets are the “Hello world.” examples from the freecodecamp What Exactly is Node.js? Explained for Beginners article.

How can I be sure that node.js is properly installed and functioning correctly?

Further reading and checking led me to think that npm was not properly installed. When I run npm -v I get the error shown in the ss below. This message led me to investigating PowerShell policies where I immediately got lost.

What should my PS Execution Policy be wrt scripts in order to use node.js and npm? Where can I find instructions for setting the Execution Policy that I need?

SS:

How did you install Node.js?

If I list the policy all I see is RemoteSigned for LocalMachine, the rest are Undefined. I would assume the command to set that is.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Your terminal is opened in G:\ and I would assume that isn’t where your script is. If you right-click an empty space inside the folder with the script file and open the terminal then run it using node, does it work? That, or add the full path to the script file.


If you just want a REPL I would suggest using Quokka

1 Like

Thank you for the reply.

First, my terminal is opened in the G: drive because that is where all my code relevant to the post is located; so your assumption is incorrect.

As to how I installed node.js, I found the web page, downloaded the install files for windows and installed them. I’ve slept more than twice since; so I cannot tell you any more, but I am curious as to why you asked the question. Does it matter how it was intalled?

Next, I don’t understand this statement:
"If I list the policy all I see is RemoteSigned for LocalMachine, the rest are Undefined. I would assume the command to set that is.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Blockquote
I have no clue what you refer to. Are you saying that you listed a policy on my machine? If so, how? Clearly, there are no such policies evident in the ss I posted of results in my terminal window.

Finally, I don’t understand the reference to REPL and Quokka. I know too little to make any sense of that statement.

My initial objective was to learn about node.js so that I can use it for server-side processing of form input data. Ultimately I will, no doubt, want to make use of node.js to retrieve data and pass it to the client-side for display. It was in pursuit of that knowledge that I found a freecodecamp article that includes examples of node.js code. In trying to copy and execute those examples, I encountered error messages. In pursuing what they messages meant, I encountered the issue of execution policies in PS that might have caused those errors. It was problems encountered in trying to change those policies that prompted my op.

Please, don’t misinterpret my ignorance on the subject as criticism in any way of your response.

Since my op, I’ve continued to search and read and watch videos. Because I was not making any headway and because one of the error messages I encountered inferred that I was not running CMD with Adminstrator privileges, I decided to close that instance of the powershell and open a new one. In that new terminal with admin privileges, I can get a version number for both node.js and npm using node -v and npm -v; so I am guessing that both are properly installed. I did not, try to uninstall and reinstall either of them but simply closed and started a new terminal session. Strangely, with this instance of the PS terminal, I cannot run the Set-ExecutionPolicy -list command. I get a message saying it is not recognized as an internal or external command, operable program, or batch file. I’ve been looking to see if Rod Serling (Host of the old TV show, The Twilight Zone) has been here.

I would think the default options for the installer would allow you to use it without issues. Unless you changed some options. You should not need admin privileges to run node or npm.


If you follow the link in the error message, it takes you to a page about PowerShell execution policies.

I ran the command Get-ExecutionPolicy -List and that is what it showed me on my machine (in a non-admin terminal).

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned

In the image you posted, your list is all Undefinded.

about_Execution_Policies

To remove the execution policy for a particular scope, set the execution policy to Undefined.

If no execution policy is set in any scope, the effective execution policy is Restricted, which is the default for Windows clients.

The command I posted would set LocalMachine to use RemoteSigned, which, as said, is what I see on my machine.


I use a Node version manager, I might suggest you do the same, I’m still using nvm-windows but I know there are newer options.

1 Like

I got it sorted. I’m not sure how but it happened after I once again opened a new terminal window. This time I opened a terminal window with Admin privileges instead of PowerShell. At first I couldn’t get the Set-ExecutionPolicy -list command to run, but a little seaching revealed an article saying to use Get-ExecutionPolicy -list instead. That worked and revealed that a former change to set the localhost policy to RemoteSigned had worked. I can now run the sample .js files using node filename.js.