javascript ReferenceError: document is not defined How to set vs code to run in the browser instead of node.js?

417 Views Asked by At

Whenever I try to access the document object in vs code I get ReferenceError: document is not defined. It seems the problem is code running in node.js which doesn't have the document thing.

My question is how do I set the vs code to run on the browser only, to be able to access DOM elements. I have installed Live server extension but the code still runs in node.js which gets me the error and I can`t properly check if the code is working the way I want. So please.. How do I solve this problem? How do I change the runtime environment in vs code?

1

There are 1 best solutions below

0
L'Ange Déchu On

You don't need a server to do this.

Open the HTML file directly inside of the browser.

It will execute your scripts as Common JS.