question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: connection.end is not a function

See original GitHub issue

Hi! When I use this code:

var config = {
    host     : 'localhost',
    user     : 'root',
    password : 'root',
    database : 'mydb',
    timezone: 'utc',
    multipleStatements: true  
  }; 
    var connection; 
    var mysql = require('promise-mysql'); 
	mysql.createConnection(config
	).then(function(conn){
		 connection = conn;
         var sql = "Select COUNT(*) From mydb";
		 var result = connection.query(sql);
		 return result;  
	}).then(function(result){ 
		connection.end();
		connection = {}; 
	}).catch(function(error){
		if (connection && connection.end) connection.end();  
	}); 

I’ve got error - TypeError: connection.end is not a function Why end is not a function? My nodejs version 8.10.0 Can anybody help me? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bitov27commented, Feb 22, 2019

Hi! Thank you guys! I had decided this problem!!!

0reactions
ghostcommented, Aug 28, 2020

Hello,

I don’t know if you resolve your problem but i have the same error using sequelize-pool. If you do a console.log for connection variable you can view that end method isn’t defined now. Instead of this method you can use connection.close().

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodejs- TypeError: connection.connect is not a function
I am planning to use connection pooling instead of single connection, heard it allows us to reuse existing database connections instead of ...
Read more >
TypeError: connection.end is not a function · Issue #102 - GitHub
Hi! When I use this code: var config = { host : 'localhost', user : 'root', password : 'root', database : 'mydb', timezone:...
Read more >
Node.js with MySQL - w3resource
You can terminate a connection by calling the end() method : connection.end(function(err) { // The connection is terminated now });. This will ...
Read more >
Connecting to the MySQL Database Server from Node.js
This tutorial shows you how to connect to the MySQL database server from a node.js application using the mysql module API.
Read more >
Connection Pools with MariaDB Connector/Node.js (Promise ...
The createPool(options) function does not return a Promise , and therefore must be wrapped in a new Promise object if returned directly from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found