My app has to connect to a mysql database but i am stuck just in that moment i cant connect it, im using a method that transforms callbacks code to promise code thats the reason i need to use async and await also the man of the tutorial doesnt have any error i guess because he has diferent terms on the keys.js, he is on linux, root user and also he has a password, things that i dont have. I really need hel thank you.
This is the code that is giving problems:
const express= require('express');
const router= express.Router();
const pool = require('../database');
router.get('/add', (req,res) =>{
res.render('casas/add');
});
router.post('/add', async (req,res) => {
const {titulo, precio, direccion, numhab, superficie} = req.body;
const nuevoPiso={
titulo,
precio,
direccion,
numhab,
superficie
};
await pool.query('INSERT INTO PISOS set ?', [nuevoPiso]);
res.send('recibido');
});
module.exports=router;
The problem is on the await line because if I delete that and the async word it works perfectly but obviously without that I cant send the elements to the database. The error that gives me the terminal is this:
(node:9548) UnhandledPromiseRejectionWarning: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'Axell'#'localhost' (using password: NO)
at Handshake.Sequence._packetToError (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
--------------------
at Protocol._enqueue (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:202:8)
at internal/util.js:297:30
at new Promise (<anonymous>)
at Pool.query (internal/util.js:296:12)
at C:\Users\Axell\Desktop\node-sql-app\src\routes\casas.js:20:15
at Layer.handle [as handle_request] (C:\Users\Axell\Desktop\node-sql-app\node_modules\express\lib\router\layer.js:95:5)
(node:9548) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9548) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
POST /casas/add - - ms - -
(node:9548) UnhandledPromiseRejectionWarning: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'Axell'#'localhost' (using password: NO)
at Handshake.Sequence._packetToError (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
--------------------
at Protocol._enqueue (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:202:8)
at internal/util.js:297:30
at new Promise (<anonymous>)
at Pool.query (internal/util.js:296:12)
at C:\Users\Axell\Desktop\node-sql-app\src\routes\casas.js:20:15
at Layer.handle [as handle_request] (C:\Users\Axell\Desktop\node-sql-app\node_modules\express\lib\router\layer.js:95:5)
(node:9548) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
POST /casas/add - - ms - -
I dont know where the error is maybe on my keys.js where i have this im on windows that is my username but I dont have a password:
module.exports={
database:{
host:'localhost',
user:'Axell',
database: 'casas',
password: ''
}
};
Here you can download the whole app it is unfinished because I cant continue due to this error: https://mega.nz/#!LAwgwAQK!OiuBqH4qxyT5CW2xRSUXdmhpfRyTtf3TobmYw-NqIic
Thank you so much!
The issue you are having is unrelated to async/await.
The credentials to MySQL incorrect. This could be an incorrect username, an incorrect password or perhaps you did not grant the Axell permission to access the casas database.
Given that you're on localhost, you can test this without localhost. Just try logging on with the same credentials with some other mysql tool (such as the mysql) tool, and you should get a similar error.
Related
This question already has answers here:
MongooseError - Operation `users.findOne()` buffering timed out after 10000ms
(17 answers)
Closed 1 year ago.
My js file wont respond and it will trow me this error in the console wich i don't understand:
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Backend server is running
Connected to MONGODB
(node:5282) UnhandledPromiseRejectionWarning: MongooseError: Operation
`users.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/home/francesco/Desktop/Projects/Social Network/NODE-REST-
API/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149:23)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5282) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch block, or
by rejecting a promise which was not handled with .catch(). To terminate the node
process on unhandled promise rejection, use the CLI flag `--unhandled-
rejections=strict` (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5282) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated.
In the future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.
This is the code of the module (btw dont mind but th "ok" its for testing.
const router = require("express").Router();
const User = require("../models/User")
//REGISTER
router.get("/register", async (req,res)=>{
const user = await new User({
username:"john",
email:"john#gmail.com",
password:"123456"
})
await user.save();
res.send("ok");
});
module.exports = router
the syntax is right, needed to format it for containing on the "code" on the question.
Thanks in advance, Francesco
You are trying to call the model without even establishing a connection with the database. You need to use async/await with connect() or createConnection().
I am trying to run my index.js file which runs my bot.js file. When I did node index.js, I got this error. Index.js is sharding my bot.js file (discord.js)
(node:7284) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_DIED]: Shard 0's process exited before its Client became ready.
at Shard.onDeath (C:\Users\Sochum\Desktop\BobloxBot\node_modules\discord.js\src\sharding\Shard.js:158:16)
at Object.onceWrapper (events.js:422:26)
at Shard.emit (events.js:315:20)
at Shard._handleExit (C:\Users\Sochum\Desktop\BobloxBot\node_modules\discord.js\src\sharding\Shard.js:384:10)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
(node:7284) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 7)
It doesn't actually say what the error is. Here is my index.js code:
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', {
totalShards:4,
token: "#",
})
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();
Here is my bot.js file code
https://pastebin.com/RW8abmKP
I am not sure why I am getting this error, but It might have something to do with the code starting in bot.js
new EconomyClient().start(require(`./config`).token, './commands', './index');
The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.
I am using Bull to process send out mails when hasura sees an update on the table and triggers the payload to the email microservice.
The issue is, that although the hasura successfully sends the payload, the controller is unable to queue the information if redis is not running on localhost:6379 even when I am running redis on 6380 and specifying it in
BullModule.registerQueue({ name: MAIL_QUEUE, redis: {host: 'localhost', port: 6380 })
On top of that, if there is a redis instance running on 6379, then Bull completely ignores the parameters I use inside the registerQueue, and works smoothly using redis 0n 6379, somehow.
For reproduction :
mail.module.ts
#Module({
imports: [
BullModule.registerQueue({ name: MAIL_QUEUE, redis: REDIS_QUEUE_URL }),
UserModule
],
controllers: [MailController],
providers: [MailService, MailProcessor],
})
export class MailModule {}
mail.processor.ts
#Processor(MAIL_QUEUE)
export class MailProcessor {
constructor(
private readonly mailService: MailService,
private readonly userService: UserService,
) {}
#Process('mail_principal_on_school_create')
async mailPrincipalOnSchoolCreate(job: Job) {
const schoolname = job.data.schoolname;
const email = job.data.email;
const firstname = job.data.firstname;
const lastname = job.data.lastname;
await this.mailService.sendMail(
{
name: `${firstname} ${lastname}`,
schoolname: schoolname,
email: email,
},
POSTMARK_MAIL_PRINCIPAL_ON_SCHOOLCREATE_TEMPLATE_ID,
);
}
}
user.service.ts
#Injectable()
export class UserService {
constructor(
#InjectQueue(MAIL_QUEUE) private mailQueue: Queue,
){}
async mailPrincipalOnSchoolCreate(data) {
const school_name = data.event.data.new.name;
const email = data.event.data.new.principal_email;
const firstname = data.event.data.new.principal_name;
const lastname = data.event.data.new.principal_surname;
this.mailQueue.add('mail_principal_on_school_create', {
email: email,
firstname: firstname,
lastname: lastname,
schoolname: school_name,
});
}
}
So the trigger from hasura reaches user.service.ts but never gets added to the queue unless there is a redis instance running on 6379.
And btw, here is the error :
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:126435) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
HELP!!
I am taking a training course, on Udemy, and it had backend code already written, as the course is purely about frontend development. It uses a very simple MongoDB database that I created. I determined that MongoDB version 4.0.10 is installed on my computer, in case that's relevant. When trying to perform a query for matching records, I get the following error:
UnhandledPromiseRejectionWarning: MongoError: FieldPath field names may not start with '$'.
at MessageStream.messageHandler (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\connection.js:268:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at TLSSocket.ondata (internal/streams/readable.js:719:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
(node:51960) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To
terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
After looking into the backend code, I found the following code that is being used to perform the query/search, and I did notice that there are $ symbols in various places.
Post.search = function(searchTerm) {
return new Promise(async (resolve, reject) => {
if (typeof(searchTerm) == "string") {
let posts = await Post.reusablePostQuery([
{$match: {$text: {$search: searchTerm}}},
{$sort: {score: {$meta: "textScore"}}}
])
resolve(posts)
} else {
reject()
}
})
}
What exactly is wrong and how do I fix it?
Identical error here. Searching from react using axios in the main app-very simple(supposed to be). It's indicative that in my case when trying to search- "open search mode" from react", mongodb server crashes with mentioned error:
f:\PrgsReact\SimplePost\backend-api\node_modules\mongodb\lib\cmap\connection.js:268
callback(new MongoError(document));
MongoError: FieldPath field names may not start with '$'.
etc..
I'm tried to change npm ver of mongodb and axios inter alia. Thanks.
I am programming in angular and create an api server in express, I have a little problem when I have been programming and making requests in the API for hours. What happens is what arrives as a maximum number of requests and throws me an error.
The operation is fine nothing fails me, it is only after a while that I get that error and for that reason the database is disconnected and my frontend in angular works.
After a while the server throws this error at me
(node:10356) UnhandledPromiseRejectionWarning: Error: ER_CON_COUNT_ERROR: Too many connections
at Handshake.Sequence._packetToError (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
--------------------
at Protocol._enqueue (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Pool.js:202:8)
at Promise (C:\xampp\htdocs\sinapsisuao\server\node_modules\promise-mysql\lib\helper.js:26:45)
at Promise._execute (C:\xampp\htdocs\sinapsisuao\server\node_modules\bluebird\js\release\debuggability.js:384:9)
at Promise._resolveFromExecutor (C:\xampp\htdocs\sinapsisuao\server\node_modules\bluebird\js\release\promise.js:518:18)
at new Promise (C:\xampp\htdocs\sinapsisuao\server\node_modules\bluebird\js\release\promise.js:103:10)
at Pool.promiseCallback (C:\xampp\htdocs\sinapsisuao\server\node_modules\promise-mysql\lib\helper.js:8:16)
at pool.query (C:\xampp\htdocs\sinapsisuao\server\node_modules\promise-mysql\lib\pool.js:57:32)
at C:\xampp\htdocs\sinapsisuao\server\build\controllers\facilitadorController.js:16:42
at Generator.next (<anonymous>)
at fulfilled (C:\xampp\htdocs\sinapsisuao\server\build\controllers\facilitadorController.js:5:58)
(node:10356) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10356) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
GET /api/facilitadores - - ms - -
OPTIONS /api/facilitadores 204 0.126 ms - 0
(node:10356) UnhandledPromiseRejectionWarning: Error: ER_CON_COUNT_ERROR: Too many connections
at Handshake.Sequence._packetToError (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\xampp\htdocs\sinapsisuao\server\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
My code database is this:
import { createPool } from "promise-mysql";
import keys from "./keys";
export async function connect(){
const connection = createPool(keys.database);
return connection;
}
And my index is:
import express, { Application } from "express";
import morgan from 'morgan';
import cors from 'cors';
import indexRoutes from './routes/indexRoutes';
import usersRoutes from './routes/users.Routes';
import emprendedorRoutes from './routes/emprendedor.Routes';
import facilitadorRoutes from "./routes/facilitador.Routes";
import consultoriaRoutes from "./routes/consultoria.Route";
import emprendimientoRoutes from "./routes/emprendimiento.Routes";
import calendarioRoutes from "./routes/calendar.Route";
import atencionRoutes from "./routes/atencion.Route";
class Server {
public app: Application;
constructor(){
this.app = express();
this.config();
this.routes();
}
//configuracion
config(): void{
this.app.set('port', process.env.PORT || 3000);
this.app.use(morgan("dev"));
this.app.use(cors());
this.app.use(express.json());
this.app.use(express.urlencoded({extended: false}));
}
//rutas
routes(): void {
this.app.use('/',indexRoutes);
this.app.use('/api/users',usersRoutes);
this.app.use('/api/emprendedores', emprendedorRoutes);
this.app.use('/api/facilitadores', facilitadorRoutes);
this.app.use('/api/consultorias', consultoriaRoutes );
this.app.use('/api/emprendimientos', emprendimientoRoutes );
this.app.use('/api/calendar', calendarioRoutes);
this.app.use('/api/atencion', atencionRoutes)
}
//inicia servidor
start(): void{
this.app.listen(this.app.get('port'), ()=>{
console.log('Server on port', this.app.get('port'));
console.log("Conectados a la BD");
});
}
}
const server = new Server();
server.start();
Someone, who can help me with this problem, only appears when I have been programming for a while.
max_connect_errors defaults to 100. When you are using connection pools this means a number of sparatic errors can quickly add up to 64 resulting in the error experiences.
Solution part 1: remove the connection pooling. Simple per connection is ok.
Solution part 2: increase max_connect_errors to its documented maximium
Solution part 3: try to identify some of the errors that occur and see if they are programmatic mistakes or transient network connection problems.