Control an ipfs node daemon using Node.js
Install:
npm install --save ipfsd-ctl
The current go ipfs version used is v0.4.3-rc3
IPFS daemons are already easy to start and stop, but this module is here to do it from javascript itself.
// start a disposable node, and get access to the api
// print the node id, and kill the temporary daemon
// IPFS_PATH will point to /tmp/ipfs_***** and will be
// cleaned up when the process exits.
const ipfsd = require('ipfsd-ctl')
ipfsd.create((err, node) => {
if (err) throw err
node.startDaemon((err) => {
if (err) throw err
const ipfs = node.apiCtl()
ipfs.id((err, id) => {
console.log(id)
process.kill()
})
})
})
The daemon controller safely spawns the node for you and exposes you an ipfs API client through node.apiCtl()
. If the parent process exits, the daemon will also be killed ensuring that the daemon isn't left hanging.
This module works by downloading the binary once, on first use, if it detects that no current binary is available to use. So keep in mind that the first command executed might throw in some overhead.
If you want to use an existing ipfs installation you can set $IPFS_EXEC=/path/to/ipfs
to ensure it uses that.
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.