Reputation: 15
I'm new to javascript. Whenever I want to run my program from vs code, I click F5 and then select chrome. As this took a little more time, I thought I could edit the launch.json file. But when I used the suggestion vs code offered me, Chrome says that local host refused to connect. I don't what I did wrong. Can you help me? My JavaScript file:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type = "text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
My launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
Upvotes: 0
Views: 2546
Reputation: 46
In the VSCode marketplace there is an extension called "Live Server":
(available here: https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) that will allow you to start your code in a server. Once you get it from the marketplace, you can right-click and select "Open with Live Server" in the HTML file to start your code.
It will begin on 5500 or 5501 (but that can be changed later in settings). This extension is one of many options but it works really well.
Upvotes: 1