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?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.