Q:

How to fix Uncaught ReferenceError: require is not defined

I tried to fetch to get some data. I want to run in chrome browser.
When I try to fetch to reach out such data,I suffered error like
require is not defined
I found question below and I trying to usescript tag,
Client on node: Uncaught ReferenceError: require is not defined
But I couldn't find out what kind of file should be loaded.
If someone know scripttag solution, please let me know.
Thanks

const fetch = require("node-fetch");

var apikey="https://opentdb.com/api.php?amount=10";

fetch(apikey)
  .then(response => response.json())
  .then(json => {
    // console.log(json);
    console.log(json.results[0].question);
  });

A:

You don´t need to import fetch, its part of JS.

var apikey="https://opentdb.com/api.php?amount=10";

fetch(apikey)
  .then(response => response.json())
  .then(json => {
    // console.log(json);
    console.log(json.results[0].question);
  });

