# 'Undefined' error when using simple DHT commands

**URL:** <https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630>\
**Category:** Help\
**Tags:** js-ipfs, dht\
**Created:** [April 3, 2020, 9:43pm UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630 "2020-04-03T21:43:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferru97](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@ferru97](https://discuss.ipfs.tech/u/ferru97)\
**Post date:** [April 3, 2020, 9:43pm UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/1 "2020-04-03T21:43:04Z")

</div>

I’m trying to run simple DHT commands on nodejs but it returns the following error:  
`(node:17640) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'findPeer' of undefined`

The simple code i’m using is:  
`const node = await IPFS.create()`  
`const result = await node.dht.findPeer( `peerId`)`

I’m not having problems with other commands such as SWARM PEERS

Thanks for support

---

<div class="post-metadata">

**Author:** ![achingbrain](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/achingbrain/32/3083_2.png) [@achingbrain](https://discuss.ipfs.tech/u/achingbrain)\
**Post date:** [April 6, 2020, 9:06am UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/2 "2020-04-06T09:06:29Z")

</div>

Sorry to hear you are having problems - what version of ipfs are you using?

---

<div class="post-metadata">

**Author:** ![ferru97](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@ferru97](https://discuss.ipfs.tech/u/ferru97)\
**Post date:** [April 6, 2020, 4:44pm UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/3 "2020-04-06T16:44:17Z")

</div>

I’m using the 6.14.4. Also I’ve noticed that the **ipfs.swarm.peers** return very few peers compared to the same command executed with **ipfs-http-client**

---

<div class="post-metadata">

**Author:** ![stebalien](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/stebalien/32/156_2.png) [@stebalien](https://discuss.ipfs.tech/u/stebalien)\
**Post date:** [April 6, 2020, 6:05pm UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/4 "2020-04-06T18:05:22Z")

</div>

6.14.4 of of what? The latest js-ipfs version is 0.42.0.

---

<div class="post-metadata">

**Author:** ![ferru97](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@ferru97](https://discuss.ipfs.tech/u/ferru97)\
**Post date:** [April 6, 2020, 8:28pm UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/5 "2020-04-06T20:28:46Z")

</div>

Oh sorry, looking with npm I can see that i’m using **ipfs v0.42.0** and **js-ipfs 0.0.301**

---

<div class="post-metadata">

**Author:** ![achingbrain](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/achingbrain/32/3083_2.png) [@achingbrain](https://discuss.ipfs.tech/u/achingbrain)\
**Post date:** [April 9, 2020, 11:59am UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/6 "2020-04-09T11:59:35Z")

</div>

The DHT is not enabled in js-ipfs by default, you have to explicitly enable it with:

```javascript
const node = await IPFS.create({
  libp2p: {
    config: {
      dht: {
        enabled: true
      }
    }
  }
})

```

Though there’s a regression in the current js-ipfs release that means you can’t enable it, even with the above config (will be fixed by [ipfs/js-ipfs#2976](https://github.com/ipfs/js-ipfs/pull/2976).

At any rate the DHT is still considered experimental so will probably cause your node to fall over after a while.

---

<div class="post-metadata">

**Author:** ![ferru97](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@ferru97](https://discuss.ipfs.tech/u/ferru97)\
**Post date:** [April 9, 2020, 3:05pm UTC](https://discuss.ipfs.tech/t/undefined-error-when-using-simple-dht-commands/7630/7 "2020-04-09T15:05:54Z")

</div>

Ok thank you. I tried but as expected it didn’t work. I solved by switching to **ipfs-http-client** where the same command works
