I cannot run JavaScript, please help me set it up

I’ve been going through JavaScript Fundamentals as a part of Web Development 101. There is this piece of code that explains how to use JS.

<!DOCTYPE html>
  <title>Page Title</title>
  <meta charset="UTF-8"/>
    // Your JavaScript goes here!
    console.log("Hello, World!")

I tried copying it and running it using both VScode and Sublime Text 3. It didn’t work. I installed node and npm, installed JS packages on Sublime, but I cannot seem to get it working. I played around with the code (added semi-colon after console.log("Hello, World") , but to no avail. This is the message I get

/usr/bin/node ./../HTML-CSS/tets.html
Debugger listening on ws://
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
<!DOCTYPE html>

SyntaxError: Unexpected token '<'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
Process exited with code 1

I was also getting one more message, but it disappeared for some reason:

      throw err;

    Error: Cannot find module 'html2jade'

I’m going crazy here, I’m trying to fix it, but I cannot do it for the life of me

I copied your exact html into a repl.it and this is what I see:

the idea is that you should be opening this html document in your web browser then observe the output of your code in the web browser’s console. Here is a link to the repl.it I made: https://repl.it/repls/HarmfulFrizzyTraining#index.html

Basically, just open your html in your browser and open the console. You’ll see your output in the console area.

1 Like

OK, this is very helpful, thanks! I do have a follow-up, if you don’t mind. Shouldn’t we be able to run this from VScode/Sublime? I read in the intro lessons that we will be using VScode for TOP. I am quite confused why it does not work there or I am just being clumsy and don’t know how to set it up. Same thing for Sublime (which I like better than VScode)

You can run JavaScript files in VS Code and see result output in VS Code’s Output tab. But you can’t run JavaScript out of an HTML file (or… I’m not aware of how you’d do that). You’ll need to open the HTML file in your browser.

I believe that later in the curriculum you’ll be exposed to running JavaScript files in VS Code, if I’m not mistaken. This is what I use when I want to run Javascript files in VS Code: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner


Oh, I got it! You have been immensely helpful! Thanks a lot!