-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (23 loc) · 833 Bytes
/
index.js
File metadata and controls
27 lines (23 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict'
// ipfsd-ctl is used to control a go-ipfs daemon from js
// (js-ipfs isn't mature enough do to certain things like IPNS yet)
// This requires that you have go-ipfs-dep installed so that you have
// an executable to run.
const factory = require('ipfsd-ctl').create()
factory.spawn((err, ipfsd) => {
if (err) { throw err }
const ipfs = ipfsd.api
ipfs.id().then(id => {
console.log("id:", id)
}).catch(console.error)
ipfs.files.add([{
path: '/test-file.txt',
content: Buffer.from('This is my test file', 'utf-8')
}]).then(res => {
const fileHash = res[0].hash
console.log('Added file with hash:', fileHash)
return ipfs.files.cat(fileHash)
}).then(text => {
console.log('File contents:', text.toString())
}).catch(console.error)
})