来自在线MySQL数据库的数据与node.js

时间:2018-06-18 19:16:36

标签: javascript mysql node.js express

我正在构建 nodejs短信应用 。这个应用程序将在cPanel中拥有的另一个网站的MySQL数据库中获取数据(电话号码)(例如 example.org ) strong>手机,值手机。这是我到目前为止所得到的错误。请帮助说明下面任何可能的错误原因。我是初学者,正在做我的第一个项目,我将在heroku中主持。



var express  = require("express");
var mysql = require("mysql");
var app = express();

//Establishing connection
var con = mysql.createConnection({
	host:"example.org",
	user:"example_admin",
	password:"*********",
	database:"example_registerdb"
});

//Fetching the phone numbers from the phone column
con.connect(function(err){
	if(err) throw err;
	con.query("SELECT phone FROM phone", function(err, results, fields){
		if(err) throw err;
		console.log(results);
	});
});

app.get('/', function(req, res){
	res.send('Hello World');
});

var server = app.listen(3306, function(){
	console.log('Listening on port 3306');
});




以下是我在cmd中遇到的错误:

E:\Documents\Computer and Coding\PlayGround\PROJECTS\SMSAPI\index.js:15
        if(err) throw err;
                ^

Error: connect ETIMEDOUT
    at Connection._handleConnectTimeout (E:\Documents\Computer and Coding\PlayGround\PROJECTS\SMSAPI\node_modules\mysql\lib\Connection.js:419:13)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at Socket._onTimeout (net.js:420:8)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)
    --------------------
    at Protocol._enqueue (E:\Documents\Computer and Coding\PlayGround\PROJECTS\SMSAPI\node_modules\mysql\lib\protocol\Protocol.js:145:48)
    at Protocol.handshake (E:\Documents\Computer and Coding\PlayGround\PROJECTS\SMSAPI\node_modules\mysql\lib\protocol\Protocol.js:52:23)
    at Connection.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\SMSAPI\node_modules\mysql\lib\Connection.js:130:18)
    at Object.<anonymous> (E:\Documents\Computer and Coding\PlayGround\PROJECTS\SMSAPI\index.js:14:5)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

0 个答案:

没有答案