You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中运行JavaScript代码提示/bin/sh: node: command not found问题求助

Fixing "node: command not found" in VS Code's Code Runner

Hey there, let's get that annoying error sorted out—this is a super common hiccup when setting up JavaScript in VS Code, so we'll walk through it step by step.

First: Make sure Node.js is actually installed

The error means VS Code can't find the node command, which usually starts with not having Node.js installed at all. Let's check:

  • Open your system's terminal (not the one inside VS Code)
  • Run these commands:
    node -v
    npm -v
    
  • If you don't see version numbers pop up, head over to the Node.js official site and install the LTS version, following the default setup steps.

If Node is installed: Point Code Runner to the correct Node path

Sometimes VS Code can't automatically find where Node is installed, so we need to tell it explicitly:

  1. Find your Node executable path:
    • Windows: Open Command Prompt and run where node—it'll give you a path like C:\Program Files\nodejs\node.exe
    • Mac/Linux: Open your system terminal and run which node—you'll get something like /usr/local/bin/node
  2. Open VS Code settings: Press Ctrl+, (Windows/Linux) or Cmd+, (Mac)
  3. Search for Code Runner: Executor Map, then click "Edit in settings.json"
  4. In the settings.json file, find the line for "javascript"—it probably looks like this:
    "javascript": "node",
    
  5. Replace "node" with the full path you found earlier. Remember to escape backslashes on Windows:
    • Windows example: "javascript": "C:\\Program Files\\nodejs\\node.exe",
    • Mac/Linux example: "javascript": "/usr/local/bin/node",
  6. Save the file, then restart VS Code to apply the changes.

Quick troubleshooting tip

If you just installed Node.js right before opening VS Code, close VS Code completely and reopen it—sometimes the editor doesn't pick up new environment variables until it's restarted.

A tiny note on your test code

Your code is totally valid, but heads up: alert() is a browser-only API. If you run this in the terminal via Code Runner, you'll get a new error because Node.js doesn't have alert() built-in. Swap it out for console.log(admin) instead, and you'll see "John" print directly in the terminal—perfect for testing!


内容的提问来源于stack exchange,提问作者Carambaman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 05:47:47