While programming in Angular and creating an API server in Express, I encountered a minor issue after spending hours coding and making requests to the API. The problem arises when the maximum number of requests is reached, resulting in an error.
Everything works smoothly until a certain point where the error occurs and causes the database to disconnect while the frontend in Angular remains functional.
After some time, the server throws this error:
(node:10356) UnhandledPromiseRejectionWarning: Error: ER_CON_COUNT_ERROR: Too many connections
// Error details...
The function to connect to my database looks like this:
import { createPool } from "promise-mysql";
import keys from "./keys";
export async function connect(){
const connection = createPool(keys.database);
return connection;
}
And my index file includes the following configurations:
import express, { Application } from "express";
import morgan from 'morgan';
import cors from 'cors';
// Other imports...
class Server {
public app: Application;
constructor(){
this.app = express();
this.config();
this.routes();
}
// Configuration settings
config(): void{
// Configurations...
}
// Routes setup
routes(): void {
// Route definitions...
}
// Start the server
start(): void{
// Initiate server...
}
}
const server = new Server();
server.start();
If someone has experience with this issue and can provide guidance on how to solve it, please reach out as this problem tends to arise only after extended periods of programming.