Node is not recognized as an internal or external command

Node is Not Recognized as an Internal or External Command


Understanding the Error

If you’re new to Node.js and trying to run the node command in your terminal or command prompt, you might encounter the error:

'Node' is not recognized as an internal or external command, operable program or batch file.

This error means that your system cannot locate the Node.js executable because it is not added to the PATH environment variable.

Why Does This Happen?

  • Node.js is not installed on your system.
  • The Node.js installation path is missing from the system’s PATH environment variable.
  • The PATH variable is incorrectly set or corrupted.

How to Fix the Error

Follow these simple steps to resolve the issue:

1. Check if Node.js is Installed

To check if Node.js is installed, open your terminal or command prompt and run:

node -v

If Node.js is installed, this command will display the version number. If not, you’ll need to install Node.js.

2. Install Node.js

Download the latest version of Node.js from the official website. During installation:

  • Select the Add to PATH option in the setup wizard.
  • Complete the installation and restart your terminal or command prompt.

3. Add Node.js to the PATH Manually (If Required)

If you’ve installed Node.js but still see the error, follow these steps to add Node.js to your PATH manually:

For Windows Users:

  1. Press Win + R, type sysdm.cpl, and press Enter.
  2. Go to the Advanced tab and click Environment Variables.
  3. Under System Variables, find and select Path, then click Edit.
  4. Click New and add the path where Node.js is installed. For example:
    C:\Program Files\nodejs
  5. Click OK to save and restart your terminal.

For macOS/Linux Users:

Edit your shell configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.bash_profile) and add the Node.js installation directory:

export PATH=$PATH:/usr/local/bin/node

Save the file and reload your shell using:

source ~/.bashrc

4. Test the Fix

Restart your terminal and run:

node -v

If the command displays the Node.js version, the issue is resolved!

Example Scenario

Let’s say you’ve installed Node.js at C:\Program Files\nodejs, but the error persists. Follow these steps:

  1. Go to Environment Variables.
  2. Add C:\Program Files\nodejs to the PATH variable.
  3. Restart the terminal and type:
    node -v
  4. You should now see something like:
    v18.17.0

Conclusion

The “Node is not recognized” error can be frustrating but is easy to fix by properly installing Node.js and configuring the PATH variable. Follow the steps in this guide, and you’ll be able to use Node.js without any issues.