Reputation:
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
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
Reputation: 2636
Turns out a NodeJS install was required and Code Runner worked like champ. The which node
command exposed the issue
which node
node not found
sudo apt update && sudo apt install nodejs -y && sudo apt install npm -y
which node
/usr/bin/node
Upvotes: 1
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
Reputation: 3379
I had the same issue with this (very useful) extension, but the solution is straight forward.
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.
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
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
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