Reputation: 337
I have a node js App, and when i try to run the node js using local database (mysql) and i use mamp and the error shown Localhost refuse to connect
and log shown TypeError: Cannot read property 'query' of undefined
. But when i try running the node js using db in server is fine.
app.js
var mysql = require("mysql");
function Connection() {
this.pool = null;
var konek = {
host: 'localhost',
user: 'root',
password: 'root',
database: 'wmc_wahana'
};
this.init = function() {
this.pool = mysql.createPool(konek);
}
this.acquire = function(callback) {
this.init();
this.pool.getConnection(function(err, connection) {
callback(err, connection);
});
};
}
module.exports = new Connection();
server.js
var app = require('./app');
var http = require('http').Server(app);
var port = '8080';
http.listen(port, function() {
console.log('Server listening on port ' + port);
});
thank you
Upvotes: 1
Views: 1580