nodejs | getaddrinfo ENOTFOUND undefined - node.js

I'm stuck with the below error when trying to run a simple server with express.
Listening on port 3000
Error: getaddrinfo ENOTFOUND undefined
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
Error: getaddrinfo ENOTFOUND undefined
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
Application versions
node: 16.14.0
mac: 12.2.1
express: 4.17.1
express-http-proxy: 1.6.0
express-session: 1.17.0
/etc/hosts file
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
I did a lot of research and came across this issue: https://eng.uber.com/denial-by-dns/
tried with a lot of different node versions
It seems like a common problem for a lot of people.
I would appreciate any help to resolve this issue.

Related

cant access the webapp running in docker with docusaurus

I have built a docker container with docusaurus server and opened port, but the website is not accessible and throws an error like this. How do I allow all the ip address in the docusaurus server?
yarn run v1.22.19
warning package.json: No license field
$ docusaurus-start
LiveReload server started on port 35729
Docusaurus server started on port 3000
Request failed: Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect',
address: '127.0.0.1', port: 80 }

Greenlock #v4 don't create ssl sertificate

When i start node js server that are using greenlock i got this message
Listening on 0.0.0.0:80 for ACME challenges, and redirecting to HTTPS
Listening on 0.0.0.0:443 for secure traffic
Ready to Serve:
But 2 minutes later i got error message
Error cert_issue:
connect ENETUNREACH 172.31.240.54:80
code: ENETUNREACH
Error: connect ENETUNREACH 172.31.240.54:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
I use virtual server and domen that i buy on GoDaddy

Docker container connection to host's Kafka throws : Error: connect ECONNREFUSED 127.0.0.1:9092

I have a nodejs app containerized as a linux container which uses the kafka-node library.
Kafka runs on the host machine which runs windows with:
Zookeeper port : 2181
Kafka broker port : 9092
I run the the nodejs container with the following command:
docker container run --network host --name nm name:1.0
In order to connect with the host's kafka I am using the following command:
client = new kafka.KafkaClient({kafkaHost: "localhost:9092"});
But this throws :
Error: connect ECONNREFUSED 127.0.0.1:9092
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 9092
}
When I change the connect command to :
client = new kafka.KafkaClient({kafkaHost: "host.docker.internal:9092"});
I am getting :
TimeoutError: Request timed out after 30000ms
at new TimeoutError (/usr/src/app/node_modules/kafka-node/lib/errors/TimeoutError.js:6:9)
at Timeout._onTimeout (/usr/src/app/node_modules/kafka-node/lib/kafkaClient.js:491:14)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
message: 'Request timed out after 30000ms'
}
Can someone advise what I am doing wrong ?
UPDATE
When switching to a linux host machine, the above localhost methodology runs just fine .
Same problem here, but I can solve
You must set the environment variable KAFKA_ADVERTISED_HOST_NAME with your domain host.docker.internal:9092 in Kafka broker
My example:
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
hostname: 'kafka-internal.io'
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka-internal.io
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
Now I can connect inside container using kafka-internal.io:9092 :)
Not the best answer but switching to a Linux host should make the first methodology (localhost:IP) run just fine .

I am running a redis(docker image) on local nodejs application [duplicate]

This question already has answers here:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
(7 answers)
Closed 1 year ago.
i'm trying to use redis connection on local node js application but it throwing an error ---
events.js:183
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
If I understand correctly, you are running node inside a Docker container. This node process is trying to reach redis instance running at localhost.
This does not work, because container (node) has its own network stack, and 127.0.0.1 does not point to the host.
In this case you'd need to either
Run redis in its own container (and use e.g. docker-compose) OR
Change the Node connection host for redis from localhost (or 127.0.0.1) to your host IP address. See How to get the primary IP address of the local machine on Linux and OS X? for finding IP address
You are trying to connect to the wrong port. As the docker ps command says, the port where redis is listening is 32768. Connecting to that port should solve your issue.
See the official docker documentation (in particular the flag -p) for more information about customizing port listening.
You can also resolve this error by redoing your Docker container, just add the "-p 6379: 6379" flag. Example (Redis with persistent date):
docker run --name some-redis -p 6379:6379 -d redis redis-server
--appendonly yes

How to connect to redis which is running on EC2, from node.js application running on local system using Express.js?

I am writing an Node.js application on Express.js. I have a Redis server installed on an EC2 instance running on UBUNTU Server 16.04. I have installed npm modules for Redis.I have mentioned the port and the host like this:-
var redis = require('redis');
var client = redis.createClient(6379,"127.0.0.1");
When I try connecting to EC2 instance of Redis, I get an error like this:-
events.js:141
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
How do I connect to redis which is running on ec2?
from the error message, it seems like redis isn't actually running on your host. i would check that redis is indeed running like this:
ps auxwg | grep redis
and check for a running redis process. another, simpler way would be to use the 'telnet' command to attempt to connect your local redis instance like:
wintermute:~ 07:52:58 melgart$ telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
in my case, redis is up and running so i get the 'connected' response. HTH

Resources