Because npm issue,so when I install other dependence the ipfs modue been deleted,so I install ipfs again.
But when execute the code below again will not happen anything after reinstall ipfs usingnpm install ipfs or yarn add ipfs.
trying to remove node_module and reinstall but still not works.
but there is a node object for console.log(node)
const IPFS = require('ipfs')
const fs = require('fs');
const node = new IPFS()
node.on('ready', () => {
node.files.add({
path: '',
content: fs.createReadStream('./sample.txt')
}, (err, result) => {
if (err) { throw err }
console.log('\nAdded file:', result[0].path, result[0].hash)
})
})
Are you sure it is the ready event? Add a console log before the node.files.add.
Yes,this code works before https://github.com/ipfs/js-ipfs/issues/1000
Found out the error
Error: can't lock file /home/.jsipfs/repo.lock: has non-zero size
at fs.stat (/home/node_modules/lock-me/src/unix.js:11:19)
at FSReqWrap.oncomplete (fs.js:123:15)
looks like the lock was left behind. just remove that file :)
Thanks,do you know which situation will generate this lock file.
Glad that worked :)
The lock file is generated every time to start the node. You need to shutdown the node graciously (with .stop) to remove it. If you kill the process, then you have to remove it manually.
Most helpful comment
looks like the lock was left behind. just remove that file :)