orbitdb / field-manual

The Offical User's Guide to OrbitDB
207 stars 43 forks source link

01_Basics.md: why do you use window.something for a nodeJS code? #143

Closed kvutien closed 3 years ago

kvutien commented 3 years ago

Thanks for the Tutorial in the field-manual. It sounds cool. I'm starting running it using nodeJS.

In the very first example I stumbled upon an issue. When I do what the code says

} catch (e) {
    window.NPP = new NewPiecePlease(window.Ipfs, window.OrbitDB)
}

my Terminal says

kvutien@VTKT5 orbitdb-ch1 % node
Welcome to Node.js v12.18.4.
Type ".help" for more information.
> const NPP = require('./newpieceplease')
Uncaught ReferenceError: window is not defined
    at Object.<anonymous> (/Users/kvutien/development/orbitdb-ch1/newpieceplease.js:13:45)

I solved it with this code instead

} catch (e) {
    /*window.*/var NPP = new NewPiecePlease(global.Ipfs, global.OrbitDB);
}

Allow me 3 questions, as a beginner:

  1. does the change I did go in the sense that was meant by the author?
  2. how about adding to the catch a console.log of the error code, because it's easy to mispell orbitDB, OrbitBD, instead of orbit-db in the require
  3. is there a real benefit for an author to make this tutorial "isomorphic"? because for the reader it's a pain to have to read all the instructions, including the part not directly interesting for a nodeJS user (respectively a browser user). I'm always reading twice to make sure I didn't skip anything related to nodeJS that I may mistake as something for the browser.

Otherwise, thanks for the tutorial. Really well done.

kvutien commented 3 years ago

On the suggestion of someone in the IPFS team (I lost his name) I tried replacing window with globalThis and it worked with node's REPL. I haven't tried with a browser.

Topic closed as far as I'm concerned (with nodeJS)

aphelionz commented 3 years ago

That was me :)

kvutien commented 3 years ago

Thanks Mark 🙂