0

I dont know whats going on. Cant find the solution through a google search. Any ideas here? I just want to be able to console.log the tools.fetch so I can see data in dev tools.

This is what I am trying to fetch ( https://www.npmjs.com/package/otter-api )

1.) JS

tools = require('otter-api');

tools.fetch().then(l => console.log(l))

2.) HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <script src="script.js"></script>
</body>
</html>

3.) In terminal: (this will create packagejson, node_module folders) npm i

and then...

npm install otter-api

4.) ENDING COMMENT I tried chnaging variable names, added const fs = require('fs') thinking that would initiate something.

important question, just how there is an npx react install to set up the entire foundation for a react file, if there also one for when working with a node project to avoid stuff like this?

DeBoer753
  • 59
  • 5
  • Does this answer your question? [Client on Node.js: Uncaught ReferenceError: require is not defined](https://stackoverflow.com/questions/19059580/client-on-node-js-uncaught-referenceerror-require-is-not-defined) – Fractalism Mar 11 '23 at 19:47

1 Answers1

1

Node JS modules are not supposed to be run directly the browser

The require function is part of Node JS. You are not running the Javascript in Node JS: you are running it in a browser.

There is more information here:

https://stackoverflow.com/a/45115226/7549483

ProfDFrancis
  • 8,816
  • 1
  • 17
  • 26