How to run javascript code in Visual studio code? /bin/sh: 1: node: not found

user7898234 picture user7898234 · Jul 8, 2017 · Viewed 12.8k times · Source

I just started learning programming and I installed Visual Studio Code to write javascript in.

I installed the Code Runner extension, to help me run my code.

Whenever I try to run my code it says:

/bin/sh: 1: node: not found

and nothing happens.

How do I fix this? I am trying to make hello world appear, but it just says node not found.

Answer

dmcquiggin picture dmcquiggin · Feb 13, 2019

I had the same issue with this (very useful) extension, but the solution is straight forward.

  1. Locate the path to your Node executable, by typing the following command in a terminal:

which node

The result will be similar to the following (I use nvm to manage my Node versions, yours might look a little different)

/home/my_username/.nvm/versions/node/v10.15.1/bin/node

Make a note of / copy this path.

  1. Open VS Code. Either press Ctrl+, (on Linux), or from the File menu, select Preferences > Settings.

In the search box at the top of this window, type:

Executor Map

Click the 'Edit in settings.json' link displayed under the first result.

Add the following to the end of the settings file, replacing the path with the one from step 1.

"code-runner.executorMap": {
            "javascript": "/home/my_username/.nvm/versions/node/v10.15.1/bin/node"
}

The Extension should now work as planned (tested on Ubuntu 18.04)