var express = require('express'),
routes = require('./routes'),
http = require('http'),
path = require('path');
var app = express();
console.log(__dirname);
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'views/')))
app.get('/', routes.index);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'test',
password : 'pass000',
database : 'testdb'
});
connection.connect();
connection.query('SELECT * from users', function(err, rows, fields) {
if (!err)
console.log('The solution is: ', rows);
else
console.log('Error while performing Query.' + err);
});
connection.end();
http.createServer(app).listen(app.get('port'), function(){
console.log('Express is running ...');
});
我的错误名为“connect ECONNREFUSED”。 我的代码在哪里出错?有任何想法纠正这个???
我搜索了这个错误,但无法找到答案:( 我正在学习enter link description here
答案 0 :(得分:1)
“ECONNREFUSED”通知您已经存在服务器运行或端口保留。所以请先杀死该实例并尝试再次运行它。