DEV Community

Amit Tiwary
Amit Tiwary

Posted on

localhost not point to correct ip address in node 18

Nodejs is becoming very popular among developers for backend development. There are lots of resources to learn it. Recently, I faced an issue when I was running my node application. I am using MySQL for the database and use MySQL npm library to connect to my database and query data. Before you start doing the query, you need to config the MySQL library and then only it can connect to your database. You must pass the IP address where your database is hosted, user name, and password. I was testing locally, so I ran the MySQL server on my machine and used the localhost as the IP address to connect to it. But I was getting the continuous error that the library was not able to make connection to SQL. After research, I found that I am using node 18 in my system and in node 18 localhost is converted to ipv6 instead of ipv4. So I need to add the IP address of localhost i.e 127.0.0.1 to connect to my local SQL server.

Top comments (0)