2

Is there any way to use an IP address instead of a domain name in node.js Request module?

I am getting the following error: [Error: Invalid URI "192.168.0.101/relay1/on"]

I know I shouldn't include the url scheme (e.g: http), so http:// 192.168.0.101/relay1/on wouldn't work either.

Below is the code generating the error:

  var arduinoRequestURL = arduinoIp + '/' + modulePrivateName + '/' + req.params.action;
  request(arduinoRequestURL, function (error, response, body) {
      console.log(body);
      console.log(error);
      console.log(response);
  });

And here is a link to the module: https://github.com/mikeal/request

1 Answer 1

1

Yes, you can. Also you must specify the protocol for request.

request('google.com', function (error, response, body) {
      console.log(body);
      console.log(error);
      console.log(response);
});

gives [Error: Invalid URI "google.com"]

The following are equivalent:

request('http://google.com', function (error, response, body) {
      console.log(body);
      console.log(error);
      console.log(response);
});
request('http://74.125.236.18', function (error, response, body) {
      console.log(body);
      console.log(error);
      console.log(response);
});
Sign up to request clarification or add additional context in comments.

3 Comments

How would you explain the following error when I add http to my URL: { [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
URL is defined as: var arduinoRequestURL = 'http://' + arduinoIp + '/' + modulePrivateName + '/' + req.params.action;
Actually it may just be that my destination is timing out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.