I am running a web server on node the code for which is given below
var restify = require(\'restify\');
var server = restify.createServer();
var quotes = [
getaddrinfo ENOTFOUND means client was not able to connect to given address. Please try specifying host without http:
var optionsget = {
host : 'localhost',
port : 3010,
path : '/quote/random', // the rest of the url with parameters if needed
method : 'GET' // do GET
};
Regarding learning resources, you won't go wrong if you start with http://www.nodebeginner.org/ and then go through some good book to get more in-depth knowledge - I recommend Professional Node.js , but there's many out there.
I can't explain why, but changing url parameter from having localhost
to 127.0.0.1
on mongodb.MongoClient.connect()
method on Windows 10 solved the issue.
Struggling for hours, couldn't afford for more.
The solution that worked for me in less than 3 minutes was:
npm install axios
Code ended up even shorter:
const url = `${this.env.someMicroservice.address}/v1/my-end-point`;
const { data } = await axios.get<MyInterface[]>(url, {
auth: {
username: this.env.auth.user,
password: this.env.auth.pass
}
});
return data;
for me it was because in /etc/hosts file the hostname is not added
var http = require('http');
var options = {
host: 'localhost',
port: 80,
path: '/broadcast'
};
var requestLoop = setInterval(function(){
http.get (options, function (resp) {
resp.on('data', function (d) {
console.log ('data!', d.toString());
});
resp.on('end', function (d) {
console.log ('Finished !');
});
}).on('error', function (e) {
console.log ('error:', e);
});
}, 10000);
var dns = require('dns'), cache = {};
dns._lookup = dns.lookup;
dns.lookup = function(domain, family, done) {
if (!done) {
done = family;
family = null;
}
var key = domain+family;
if (key in cache) {
var ip = cache[key],
ipv = ip.indexOf('.') !== -1 ? 4 : 6;
return process.nextTick(function() {
done(null, ip, ipv);
});
}
dns._lookup(domain, family, function(err, ip, ipv) {
if (err) return done(err);
cache[key] = ip;
done(null, ip, ipv);
});
};
// Works fine (100%)
I also had same problem and I fixed it by using right proxy. Please double check your proxy settings if you are using proxy network.
Hope this will help you -