Commit 734e1cac authored by Marius Momeu's avatar Marius Momeu

Add IPFS demo implemented in nodejs

parent 9bd99216
var fs = require('fs');
var w_data = "I'm just a DEMO content. Don't mind me...\n";
fs.writeFileSync("/tmp/ipfs-demo-file.txt", w_data, function(err, w_data) {
if (err) console.log(err);
});
const files = [
{
path: '/tmp/ipfs-demo-file.txt',
content: fs.readFileSync('/tmp/ipfs-demo-file.txt')
}
]
var ipfsClient = require('ipfs-http-client')
var ipfs = ipfsClient({ host: '127.0.0.1', port: '5001', protocol: 'http' })
ipfs.add(files, function (err, files) {
var demo_hash = files[0].hash;
console.log("Stored the file with hash " + demo_hash + " in IPFS");
console.log("Let's try to retrieve " + demo_hash + " now...");
ipfs.get(demo_hash, function (err, files) {
files.forEach((file) => {
console.log("Retrieved hash: " + file.path)
console.log("Retrieved content: " + file.content.toString('utf8'))
});
});
});
#!/bin/bash
mkdir ~/ipfs-docker-data/
mkdir ~/ipfs-docker-staging/
mkdir -p ~/ipfs-docker-data/
mkdir -p ~/ipfs-docker-staging/
docker run -d --name ipfs-node \
-v ~/ipfs-docker-staging:/export -v ~/ipfs-docker-data:/data/ipfs \
-p 8080:8080 -p 4001:4001 -p 127.0.0.1:5001:5001 \
jbenet/go-ipfs:latest
ipfs/go-ipfs:latest
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment