Closed keepsimple1 closed 5 years ago
Hello! Thamks for writing. As of now this code will work with Node version 11 and above. What node version are you running? I.e. the output of node --version
Looks like my node
is quite old then. It's version 8.1.2 . I will try to get it upgraded. Thanks!
A tool like nvm might make it easier: https://github.com/nvm-sh/nvm
Thanks. It turns out quite interesting:
npm install orbit-db ipfs
failed. - const Ipfs = require('ipfs')
- const OrbitDB = require('orbit-db')
+ var Ipfs = require('ipfs')
+ var OrbitDB = require('orbit-db')
I'm new to JS, but I think const
has a block scoping while var
is global. Hence Ipfs
and OrbitDB
was not visible outside the try
block?
Ah, yes! Sorry - the latest PR fixes that. You can use this in the meantime.
class NewPiecePlease {
constructor (Ipfs, OrbitDB) {
this.Ipfs = Ipfs
this.OrbitDB = OrbitDB
}
}
try {
const Ipfs = require('ipfs')
const OrbitDB = require('orbit-db')
module.exports = exports = new NewPiecePlease(Ipfs, OrbitDB)
} catch (e) {
window.NPP = new NewPiecePlease(window.Ipfs, window.OrbitDB)
}
The PR was merged so everybody should have that code update now :) Closing this but feel free to open more issues as you go through the rest of the tutorial!
Hi, I am following the Chapter 1 (https://github.com/orbitdb/field-manual/blob/master/01_Tutorial/01_Basics.md) to learn the basics, and it seems that the following try block would throw exception when running in Node.js:
Is it expected? The exception I got is (I added console.log):
And later, it will fail to find "Ipfs" and fall into the code path for the browser. (window.NPP).