How to Fix '/bin/sh: 1: node: not found' Error When Running JavaScript in Visual Studio Code with Code Runner (Beginner's Guide)
You’ve just written your first JavaScript (JS) script in Visual Studio Code (VS Code), installed the popular Code Runner extension to run it, and clicked "Run Code"—only to be greeted by a frustrating error: /bin/sh: 1: node: not found. If you’re new to coding, this error might seem intimidating, but fear not! It’s one of the most common issues beginners face when setting up their JS development environment, and it’s easy to fix once you understand the root cause.
In this guide, we’ll break down why this error occurs, walk you through step-by-step solutions to resolve it, and ensure you can run your JS code smoothly in VS Code with Code Runner. No prior technical expertise is required—we’ll explain everything in simple terms!
What Causes the '/bin/sh: 1: node: not found' Error?#
Before diving into fixes, let’s understand the error. The message /bin/sh: 1: node: not found is your computer’s way of saying: "I tried to run the 'node' command, but I can’t find it anywhere."
Here’s why this happens:
Node.js is not installed: Code Runner uses Node.js (a JavaScript runtime) to execute JS files. If Node.js isn’t installed on your system, the node command won’t exist.
Node.js is installed, but not in your system’s PATH: Even if Node.js is installed, your operating system (OS) might not know where to find the node executable. The "PATH" is a system variable that tells your OS which folders to search for executable programs (like node). If Node.js isn’t in the PATH, the OS can’t "see" it.
You’ll see two versions: LTS (Long Term Support) (recommended for most users) and Current (latest features). Click the "LTS" button to download the installer (e.g., node-v20.10.0-x64.msi).
Run the installer. When prompted, check the box: "Add to PATH" (critical for Step 4!).
Follow the installer prompts (click "Next" until finished).
Code Runner uses a "executor map" to decide how to run files. By default, it uses node for JS files, but you can explicitly set the path to Node.js if needed.
Open VS Code settings:
Press Ctrl+, (Windows/Linux) or Cmd+, (macOS) to open Settings.
Search for "Code Runner: Executor Map" and click "Edit in settings.json".
Ensure the javascript entry uses the correct node command. The default is:
"node -v" works in terminal but not in Code Runner#
Restart VS Code: VS Code may not pick up PATH changes until restarted.
Use VS Code’s integrated terminal: Code Runner uses the same terminal environment as VS Code. If node -v works in the integrated terminal but not in Code Runner, restart VS Code.
If you see EACCES: permission denied when installing Node.js, use sudo (e.g., sudo apt install nodejs) or install Node.js via nvm (Node Version Manager) to avoid permission issues.
The /bin/sh: 1: node: not found error is a common roadblock for beginners, but it’s easily fixed by installing Node.js and ensuring it’s in your system’s PATH. By following this guide, you’ve learned how to:
Check for Node.js installation,
Install Node.js on Windows, macOS, or Linux,
Verify Node.js is in your PATH,
Configure Code Runner (if needed),
Troubleshoot common issues.
Now you’re ready to run JavaScript files in VS Code with Code Runner seamlessly!