tanigross
tanigross

Reputation: 37

Error ECONNREFUSED when using fetch in Node.js

I'm using this code to try and post a request to get an authorization code to use the Nanoleaf API for the one I have at my house, but whenever I make the request with the code below, I get the error ECONNREFUSED and I'm not entirely sure why it's happening. I tried switching the port number and still no luck. The IP address in the code has an x instead of the last number, and it's the IP of the Nanoleaf. Here's the guide that shows how to make the request with the IP: https://documenter.getpostman.com/view/1559645/RW1gEcCH

var requestOptions = {
  method: 'POST',
  redirect: 'follow'
};

fetch("http://10.0.0.x/api/v1/new", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Upvotes: 0

Views: 473

Answers (2)

Tobi
Tobi

Reputation: 11

Have you tried to update your Nanoleaf to the latest firmware version via the smartphone app? I was working with the same requests recently and I got the same error and the upgrade fixed it for me. Probably there was an API update.

Please don't forget to add the default port (:16021) of Nanoleaf to your request address.

Upvotes: 1

Leone
Leone

Reputation: 13

I have the same error using the nanoleafs addon on my Homey. After removing the device in an attempt at re-adding it, it gives me an "[Object] [Object]" error. The connection still works with the native Nanoleafs Android app and the Desktop app. So maybe it's a general issue with the API.

Upvotes: 0

Related Questions