10

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.

1
  • it works fine in my enviroment. is it just simle js code or typescript? try to install nodejs first. Commented Jul 8, 2017 at 7:14

6 Answers 6

26

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)

Sign up to request clarification or add additional context in comments.

Comments

11

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

Comments

2

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.

Comments

1

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"
    }
}

Comments

1

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

Comments

0

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!

6 Comments

actualy it doesnt work. I just tried making a new program but it keeps saying the same thing when I run it. It just says this when I try it your way - node myapp.js module.js:328 throw err; ^ Error: Cannot find module '/home/david/webdev/myapp.js' at Function.Module._resolveFilename (module.js:326:15) at Function.Module._load (module.js:277:25) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3
Hmm, it looks like the node just doesn't find your app. Maybe you can try node ./myapp.js With the ./ you explicit says thats program is in that current directory, where your are in the terminal. (optionally you can leave the .js from the command, like node myapp, because nodejs will know, you want to run a javascript file)
I was confused when you said type node myapp.js. I literally typed node myapp.js, instead of the name of my file which is hiuhiu.js. When I tried node hiuhiu.js, it worked for the first time I tried it and it printed the number 42. But I changed the code in the same file to say hello world now and when I type node hiuhiu.js it says "node hiuhiu.js SyntaxError: Unexpected identifier" and a bunch of other random stuff I don't understand. All I had in my code was console.log("hello"); so I don't understand the error.
I just tryied using node ./hiuhiu.js and node hiuhiu but its just showing me ... I think I'm going to give up on making it work in visual code studios. Is there a better way to run javascript code, or a standard way people use? I was using an editor in my firefox browser earlier and it worked fine no issues, but it was hard to see my code so I downloaded visual code studios. Now my code doesn't work there.
Never give up :) It looks like the node is working fine as the first time runned your code, the second time there should be and error in your code. The quotes at good position etc? Btw, if you don't want to work in browser, that's the standard way. But you don't need the visual studio code for this. As i see you are on linux, so just start a linux terminal, navigate to your folder, then run your .js file with the node. There is no tricky setup, just need an installed nodejs, a js file, and the terminal.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.