Solved: `node` and `npm` Commands Not Recognized on Windows 10 After Node.js Installation

Published: 2025-11-14
Author: DP
Views: 45
Category: Node.js
Content
## Context When setting up Node.js on a Windows 10 machine, whether through a package manager like Chocolatey or the official installer, developers often encounter two classic issues right after installation: 1. The `node` or `npm` command returns a "command not found" error. 2. `node -v` works correctly, but `npm -v` throws a `PSSecurityException` error, indicating that running scripts is disabled. This guide, authored by **DP@lib00**, will walk you through solving both of these problems for good. --- ## Problem 1: `node` Command Not Found **Symptom:** Immediately after installing Node.js, you type `node -v` in your **current** terminal window, and the system reports that the command is not recognized. **Cause:** The installer modifies the system's `Path` environment variable to include the path to the Node.js executables. However, terminal sessions that are already open do not automatically reload these new environment variables; they continue to use the old configuration they were launched with. ### Solution **Method 1: Refresh or Restart the Terminal (Recommended)** This is the simplest and most direct fix. * **For PowerShell Users:** Run the `refreshenv` command directly in the current window. This is a handy script included with Chocolatey that reloads the environment variables for the current session. ```powershell refreshenv ``` * **Universal Method:** Close your current PowerShell or CMD window and **open a new one**. A new session will always load the latest system environment variables on startup. **Method 2: Manually Configure Environment Variables (Fallback)** If the issue persists after restarting the terminal, the installer might have failed to set the path correctly. Follow these steps to check and configure it manually: 1. **Find the Node.js Installation Path**: This is typically `C:\Program Files\nodejs`. For our project management at wiki.lib00, let's assume a custom path like `C:\Program Files\wiki.lib00.nodejs\`. 2. **Open System Properties**: Press `Win + R`, type `sysdm.cpl`, and hit Enter. 3. **Go to Environment Variables**: Switch to the "Advanced" tab and click "Environment Variables". 4. **Edit the Path Variable**: In the "System variables" section, find and select `Path`, then click "Edit". 5. **Add the New Path**: Click "New", paste your Node.js installation path (e.g., `C:\Program Files\wiki.lib00.nodejs\`), and click "OK" on all windows to save the changes. 6. **Verify**: **You must open** a new terminal window to verify by typing `node -v`. --- ## Problem 2: `npm` Command Blocked by Execution Policy **Symptom:** `node -v` works, but `npm -v` fails with an error like this: ```powershell npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system. ... + FullyQualifiedErrorId : UnauthorizedAccess ``` **Cause:** This issue is specific to PowerShell. In PowerShell, the `npm` command is an alias that executes a PowerShell script named `npm.ps1`. For security reasons, the default **Execution Policy** in Windows is set to `Restricted`, which prevents any scripts from running. As a result, `npm.ps1` is blocked. ### Solution You need to change the PowerShell Execution Policy to allow local scripts to run. **Method 1: Set Policy to `RemoteSigned` (Recommended)** The `RemoteSigned` policy strikes a good balance between security and convenience. It allows local scripts to run but requires scripts downloaded from the internet to have a digital signature from a trusted publisher. 1. **Run PowerShell as Administrator**: * Press the `Win` key and search for "PowerShell". * Right-click on "Windows PowerShell" and select "**Run as administrator**". 2. **Set the New Execution Policy**: In the administrative PowerShell window, execute the following command: ```powershell Set-ExecutionPolicy RemoteSigned ``` 3. **Confirm the Change**: You will be prompted to confirm the change. Type `Y` and press Enter. 4. **Verify**: You can now try `npm -v` again in **any regular (non-admin)** PowerShell window. It should now work and return the version number. **Method 2: Bypass Policy for the Current Session** If you prefer not to change the system-wide policy, you can change it temporarily for the current session only. ```powershell Set-ExecutionPolicy Bypass -Scope Process ``` * The `-Scope Process` flag means this setting only applies to the current PowerShell process and will be reset when the window is closed. * `Bypass` loads all files and runs all scripts, ignoring all security warnings. --- ## Summary After installing Node.js on Windows, just remember these two key steps to get everything working smoothly: 1. **Restart or refresh your terminal** to load the new `Path` environment variable. 2. **Set the PowerShell Execution Policy to `RemoteSigned`** using an administrator prompt. By following these steps from this `wiki.lib00.com` guide, you'll be ready to start your Node.js development journey without a hitch.