# How to reset the lock file programmatically in ipfs 0.41.1

**URL:** <https://discuss.ipfs.tech/t/how-to-reset-the-lock-file-programmatically-in-ipfs-0-41-1/7363>\
**Category:** Help\
**Created:** [February 25, 2020, 8:34pm UTC](https://discuss.ipfs.tech/t/how-to-reset-the-lock-file-programmatically-in-ipfs-0-41-1/7363 "2020-02-25T20:34:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emclab](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/emclab/32/3432_2.png) [@emclab](https://discuss.ipfs.tech/u/emclab)\
**Post date:** [February 25, 2020, 8:34pm UTC](https://discuss.ipfs.tech/t/how-to-reset-the-lock-file-programmatically-in-ipfs-0-41-1/7363/1 "2020-02-25T20:34:03Z")

</div>

My app has a simple method to retrieve content with CID passed in (node 12.16.0 on windows10). Here is the method:

retrieveFromIpfs: async function(cid) {

```
const ipfs_node = await IPFS.create();

try {

    const fileBuffer = await ipfs_node.cat(cid)

    return fileBuffer;

} catch(err) {

    console.log("Error retrieving file from IPFS : ", err);

    return '';

}

```

}

The app saved a string of “test ipfs saving” to ipfs and retrieve it back with the CID:

//retrieve

router.post(‘/retrieve’, , async (req, res) =\> {

```
try {

    const data = await helper.retrieveFromIpfs(req.cid)

    console.log("ipfs data retrieved : ", data.toString());

    return data;  

} catch (err) {

    console.log("error in retrieving ipfs file ", err);

    return res.status(400).send(err.message);

}

```

} )

First time it returns `Object [AsyncGenerator] {}`. If try 2nd time, then there is file locked error.  
Here is the error on the node console:

Listening on port 3000…  
Executing (default): SELECT 1+1 AS result  
DB connection has been established successfully.  
Swarm listening on /ip4/192.168.1.6/tcp/4002/p2p/QmVxfGtbh95P1yiNVL9TmEm1tZm7SjcFbLo6UbG6SEfHJc  
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/QmVxfGtbh95P1yiNVL9TmEm1tZm7SjcFbLo6UbG6SEfHJc  
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/QmVxfGtbh95P1yiNVL9TmEm1tZm7SjcFbLo6UbG6SEfHJc  
ipfs data retrieved : Object [AsyncGenerator] {}  
error in retrieving ipfs file Error: Lock file is already being held  
at C:\d\code\js\emps\_bbone\node\_modules\proper-lockfile\lib\lockfile.js:68:47  
at callback (C:\d\code\js\emps\_bbone\node\_modules\graceful-fs\polyfills.js:295:20)  
at FSReqCallback.oncomplete (fs.js:167:5) {  
code: ‘ELOCKED’,  
file: ‘C:\Users\JunC\.jsipfs’  
}

Here is the example code followed on github: [ipfs-node-example/index.js at master · indreklasn/ipfs-node-example · GitHub](https://github.com/indreklasn/ipfs-node-example/blob/master/index.js)

---

<div class="post-metadata">

**Author:** ![emclab](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/emclab/32/3432_2.png) [@emclab](https://discuss.ipfs.tech/u/emclab)\
**Post date:** [February 26, 2020, 7:04am UTC](https://discuss.ipfs.tech/t/how-to-reset-the-lock-file-programmatically-in-ipfs-0-41-1/7363/2 "2020-02-26T07:04:38Z")

</div>

Here is the portion of package.json:

“dependencies”: {

```
"@hapi/joi": "^17.1.0",

"compression": "^1.7.4",

"cors": "^2.8.5",

"dotenv": "^8.2.0",

"express": "^4.17.1",

"express-async-errors": "^3.1.1",

"helmet": "^3.21.2",

"ipfs": "^0.41.1",

"jsonwebtoken": "^8.5.1",

"moment": "^2.24.0",

"moment-timezone": "^0.5.27",

"nexmo": "^2.6.0",

"nodemon": "^2.0.2",

"pg": "^7.18.2",

"pg-hstore": "^2.3.3",

"randomstring": "^1.1.5",

"sequelize": "^5.21.5",

"socket.io": "^2.3.0",

"winston": "^3.2.1"

```

},

---

<div class="post-metadata">

**Author:** ![hugomrdias](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/hugomrdias/32/6635_2.png) [@hugomrdias](https://discuss.ipfs.tech/u/hugomrdias)\
**Post date:** [February 27, 2020, 12:28pm UTC](https://discuss.ipfs.tech/t/how-to-reset-the-lock-file-programmatically-in-ipfs-0-41-1/7363/3 "2020-02-27T12:28:02Z")

</div>

Hi @emclab js-ipfs recently moved to an streaming api with async iterable more info here [https://blog.ipfs.io/2020-02-13-js-ipfs-0-41/](https://blog.ipfs.io/2020-02-13-js-ipfs-0-41/) for your specific case you need to consume the async generator more info in the docs here [https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#cat](https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#cat)

If you have any more questions feel free to ping us again.

---

<div class="post-metadata">

**Author:** ![emclab](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/emclab/32/3432_2.png) [@emclab](https://discuss.ipfs.tech/u/emclab)\
**Post date:** [February 27, 2020, 6:34pm UTC](https://discuss.ipfs.tech/t/how-to-reset-the-lock-file-programmatically-in-ipfs-0-41-1/7363/4 "2020-02-27T18:34:29Z")

</div>

Many thanks. There is another ipfs example showing use `all` to assemble the iterables to form a data stream. Also after calling `node.stop()` when closing, the file locked error disappeared.
