Guest User

Untitled

a guest
May 30th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. var mysql = require('mysql')
  2. var pool = mysql.createPool({
  3. connectionLimit: 10,
  4. host: 'localhost',
  5. user: 'root',
  6. password: 'password',
  7. database: 'my_database'
  8. })
  9.  
  10. // Ping database to check for common exception errors.
  11. pool.getConnection((err, connection) => {
  12. if (err) {
  13. if (err.code === 'PROTOCOL_CONNECTION_LOST') {
  14. console.error('Database connection was closed.')
  15. }
  16. if (err.code === 'ER_CON_COUNT_ERROR') {
  17. console.error('Database has too many connections.')
  18. }
  19. if (err.code === 'ECONNREFUSED') {
  20. console.error('Database connection was refused.')
  21. }
  22. }
  23.  
  24. if (connection) connection.release()
  25.  
  26. return
  27. })
  28.  
  29. // Promisify for Node.js async/await.
  30. pool.query = util.promisify(pool.query)
  31.  
  32. module.exports = pool
Add Comment
Please, Sign In to add comment