Reputation: 51
I'm trying to run this simple code in Visual Studio Code for learning JavaScript, but I keep getting this error:
[Running] node "/path/to/tempCodeRunnerFile.javascript" /bin/sh: node: command not found
[Done] exited with code=127 in 0.014 seconds
I've looked online and have tried changing the CodeRunner Executable Map as I saw in another post but it doesn't seem to be helping.
let admin, name; // can declare two variables at once
name = "John";
admin = name;
alert(admin); // "John"
Upvotes: 5
Views: 19444
Reputation: 625
in this page: How to run javascript code in Visual studio code? /bin/sh: 1: node: not found
dmcquiggin had resolve this problem:
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.
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"
}
this also works on my mac, cheers
Upvotes: 5
Reputation: 500
First of all, check the output of which node
in the default terminal application. If the output is empty, this means that the path where the node
binary resides is not in your $PATH
.
Try to find the location of the node
executable. After this, check what's the shell you're using by running echo $SHELL
. If it returns something like /bin/bash
, create a file(may already exist) named ".bash_profile" or ".bashrc" and there, add the following: export PATH=$PATH:<location of node>
, replacing <location of node>
with the actual location of the node binary.
Upvotes: 2