Till now I was using require to import the npm installed moudles but, when I use import, my modules are being imported but I am not able to fetch the component of my html file.
here is my html code,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My Hello World</title>
<link rel="stylesheet" type="text/css" href="index.css" />
</head>
<body>
<p id="value"></p>
<h1 style="margin: auto">Working</h1>
<script type="module" src="index.js"></script>
</body>
</html>
here is my js file(index.js)
import { faker } from "@faker-js/faker";
var pval = document.getElementById("value");
.....
when I run node index.js it shows,
var pval = document.getElementById("value");
^
ReferenceError: document is not defined
at file:///D:/alchemy%20practical/javascript%20fundamental/node/index.js:3:12
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
any idea why I'm getting this error?
I mentioned the type as module in my package.json and searched a lot on internet but no one was mentioning this problem.