简体   繁体   中英

Can't connect to database NestJS NodeJS

I'm having issues with nestJS projects, it just won't connect to any database so far.

I was working with MySQL so I tried to restart an older working project (which was working fine like 1 week ago) with MongoDB and it's failing the same way.

This is what I get on the MongoDB project :

  • Angular : An error occurred while proxying request localhost:4200/auth to http://localhost:3000/ [ECONNREFUSED]

  • NetJets says it can't connect to the database.

And on the MySQL project I get with nestJs :

  • ERROR [TypeOrmModule] Unable to connect to the database. Retrying (3)... Error: connect ECONNREFUSED 127.0.0.1:3306 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)

I'm using : Windows 11 Angular CLI: 14.0.6 Node: 16.16.0 Package Manager: npm 8.14.0 NestJS: 9.0 .

I think the problem comes from nestJS but I have no clue where and what to do about it.

Thanks

Port 3306 is the default MySQL port. localhost is synonymous with IP address 127.0.0.1, but I've known system not resolve localhost to that IP address and its necessary to use the IP address explicitly (127.0.0.1 is loopback). All of this assumes that you have a MySQL server running on the same machine as the web server, and that its configured for the matching port. You may also need to supply authentication to connect to the MySQL instance.

You should have a config file that is either included into the project sources, or perhaps injected via the environment that has the MySQL connection details, or it might be missing and using defaults that aren't good for your system. NB It's common to exclude the config details from source control systems to avoid checking in authentication secrets or other private info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM