Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 36e2280

Browse files
committed
Improve IPFS finding in example
1 parent 610fd7a commit 36e2280

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,9 @@ There's still a bit of work required to start up a node in a robust way (i.e. wi
118118

119119
```javascript
120120
// Find the IPFS implementation
121-
var IPFS
122-
if (!(typeof require === 'undefined')) {
123-
// Can load through Node
124-
IPFS = require('ipfs')
125-
} else if (!(typeof Ipfs === 'undefined')) {
126-
// Can load through browser global
127-
IPFS = Ipfs
128-
}
121+
const IPFS = typeof Ipfs !== 'undefined' ? Ipfs // browser global
122+
: typeof require === 'function' ? require('ipfs') // cjs require
123+
: throw new Error('could not load IPFS')
129124

130125
// Make an IPFS node
131126
var ipfs = new IPFS()

0 commit comments

Comments
 (0)