user7898234
user7898234

Reputation:

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

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.

Upvotes: 10

Views: 26984

Answers (6)

Amit Gupta
Amit Gupta

Reputation: 21

If you have brew installed, then just run this on Terminal, brew install node

It will install node. Now run, which node

and you will see some thing like this, /usr/local/bin/node

Now run your program and you should be good to go.

Upvotes: 2

fusion27
fusion27

Reputation: 2636

In Ubuntu 18.04

Turns out a NodeJS install was required and Code Runner worked like champ. The which node command exposed the issue

BEFORE

which node
node not found

NODE + NPM INSTALLATION

sudo apt update && sudo apt install nodejs -y && sudo apt install npm -y

AFTER

which node
/usr/bin/node

šŸ‘ļø CODE RUNNER WORKS

Upvotes: 1

xiaomuzizier
xiaomuzizier

Reputation: 111

Please use below setting (File->Preference->Settings) to run code in Integrated Terminal:

{
"code-runner.runInTerminal": true

}

the answer from: https://github.com/formulahendry/vscode-code-runner/issues/355

Upvotes: 11

dmcquiggin
dmcquiggin

Reputation: 3379

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)

Upvotes: 25

Kranich_Ibykus
Kranich_Ibykus

Reputation: 95

The readme for the plugin says that you should add an "executorMap".

Open the user settings (on Mac Cmd + Comma, on Windows Shift+Alt+Comma) and add the following to the JSON:

{
    "code-runner.executorMap": {
        "javascript": "node"
    }
}

Upvotes: 1

aboutus
aboutus

Reputation: 239

That program looks like running a node for js. Why not just using the built in terminal in the visual studio code with nodejs?
You just need to install the nodejs: https://nodejs.org/en/
Then in visual studio code press ctrl + ` On the terminal you have to say type:
node myapp.js
Then on the terminal it prints out your data.
(that solution is more 'professional like')
Welcome in the world of JavaScript!

Upvotes: 0

Related Questions