VS Code Output on Live Server Issue

I’ve just started using VS Code as my code editor and so far I’ve been using it for JavaScript. I’ve installed the live server, but when I click on go live, it just shows a black screen with the exact code and comments I’ve written on VS Code. It doesn’t show anything in the console or the actual result of the code I’ve written. Could someone tell me how to fix it? Thanks

Hey.
Can you send a screenshot of your file names? I also found some related problems here, if they don’t offer the needed assistance, we’ll dig deeper.

Are you serving HTML? It is a web server, you can’t serve JS files.


If you want a REPL in the editor you can use the Quokka.js extension.

After I clicked on script.js, the black screen shows up with the exact code from Visual Studio

I’ve used VS Code before on another computer and I’m just redownloading it here. I don’t think I’ve done anything differently, so I’m not sure what’s wrong. What exactly do you mean by “serving HTML”?
Thanks, I’ll use the Quokka.js extension for now

I mean you have to serve an HTML file. You can link to the JS in the HTML file.

You can not serve a JS file directly.

1 Like

Oh ok. How can I link the file?

1 Like

This is basic knowledge you should seek out. The curriculum teaches it.


Create an index.html file and server it.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
    <title>Document</title>
  </head>
  <body></body>
  <!-- code inside the script.js file -->
  <script defer src="script.js"></script>

  <!-- code inside the script element -->
  <script>
    console.log("Hello World");
  </script>
</html>

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.