3

Im trying to run this simple code in VSCode for learning Javascript but I keep getting this error:

[Running] node "/var/folders/xr/30nkhmxs7159fblbjtfj2jhw0000gn/T/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.

Thanks!

let admin, name; // can declare two variables at once

name = "John";

admin = name;

alert( admin ); // "John"
Carambaman
  • 31
  • 1
  • 1
  • 2

2 Answers2

2

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.

shrihankp
  • 500
  • 2
  • 12
  • I'm sorry but how do I find the location of the node executable? – Carambaman Jan 31 '21 at 08:02
  • I inputed 'echo $SHELL' in the terminal and it did return with /bin/bash but I have no idea where or how to create the ".bash_profile" or ".bashrc" file. – Carambaman Jan 31 '21 at 08:09
  • How did you install `node`? Via `apt`/`pacman`/`dnf`/`yum`? Via manually copying files? Any other? – shrihankp Feb 01 '21 at 14:52
  • To create a .bashrc file, run the command: `touch ~/.bashrc`. Then open that file using the GUI or run `code ~/.bashrc` for VS Code, and then edit the file accordingly. – shrihankp Feb 01 '21 at 14:54
1

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

Han.Oliver
  • 525
  • 5
  • 8