I am trying to connect to the database with the promise-mysql module from express with node, my files are the following. From the console I can connect to mysql without problems, the same as using phpmyAdmin or Workbench
When executing I receive the error of
TypeError: pool.getConnection is not a function
keys.ts
export default {
database : {
host : 'localhost',
user: 'root',
password: '124563',
database: 'ng_db'
}
}
database.ts
import mysql from 'promise-mysql';
import keys from './keys';
const pool = mysql.createPool(keys.database);
pool.getConnection()
.then(connection => {
pool.releaseConnection(connection);
console.log('DB is Connected');
});
export default pool;
gameController.ts
import { Request,Response } from 'express';
import pool from '../database';
class GameController {
public index (req: Request, res: Response) {
pool.query('DESCRIBE game');
res.json('game')
}
}
export const gameController = new GameController();
export default gameController;
The problem is the version of
promise
you have , I think you are doing the Fazt tutorial (Angular Mysql CRUD Tutorial, REST API Node & Typescript) to solve it you just have to execute the command in the terminal:I had exactly the same problem and it worked for me. Greetings.