NodeJS在Mac上运行,在centOS上部署时发生错误 [英] NodeJS running on Mac, and have an error occurred when deploying on centOS

查看:197
本文介绍了NodeJS在Mac上运行,在centOS上部署时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Node.js和MySQL的项目.该项目在本地MAC osx上运行良好.但是在centOS服务器上部署时发生错误.该项目有2个部分,其中1个是使用cron自动运行的,它可以从一个网站自动获取数据,并将此数据更新到MySQL中.这部分在本地和联机服务器上都可以正常工作.但是另一部分不是,那部分是浏览器上的显示UI,但是访问它时会显示错误.

I have a project with Node.js and MySQL. This project run well on local MAC osx. But have an error occurred when deploying on the centOS server. The project have 2 part, 1 is auto run with cron, that auto get data from one web, and update this data into MySQL. This part works fine on both local and online server. But another part is not, that part is display UI on browser, but when accessing it, an error is displayed.

Error: Cannot enqueue Query after fatal error.
    at Protocol._validateEnqueue (/home/xx/node_modules/mysql/lib/p rotocol/Protocol.js:193:16)
    at Protocol._enqueue (/home/xx/node_modules/mysql/lib/protocol/ Protocol.js:129:13)
    at Connection.query (/home/xx/node_modules/mysql/lib/Connection .js:185:25)
    at SessionStore.get (/home/xx/node_modules/express-mysql-sessio n/lib/index.js:92:18)
    at session (/home/xx/node_modules/express-session/index.js:348: 11)
    at Layer.handle [as handle_request] (/home/xx/node_modules/expr ess/lib/router/layer.js:82:5)
    at trim_prefix (/home/xx/node_modules/express/lib/router/index. js:270:13)
    at /home/xx/node_modules/express/lib/router/index.js:237:9
    at Function.proto.process_params (/home/xx/node_modules/express /lib/router/index.js:312:12)
    at /home/xx/node_modules/express/lib/router/index.js:228:12

(此错误同时显示在控制台日志和浏览器上,此后该项目仍在运行,所以我猜这来自MySQL).

(this error displayed on both console log and the browser, the project still running after that, so i guess this came from MySQL).

这是sql连接文件:简单的是

This is the sql connect file: simple is

var config = require('./config');
var mysql = require('mysql'),
    host = config.hostName,
    user = config.databaseUser,
    password = config.databasePassword,
    database = config.databaseName;

module.exports =  mysql.createPool({
  connectionLimit : 10,
  host: host,
  user: user,
  password: password,
  database: database
});

这就是我所说的:

imgExport.selectLast = function(callback){
  conn.getConnection(function(err,conn) {
    querySelectLast15Secon = "SELECT * FROM image WHERE year(moderate_time) = year(curdate()) AND month(moderate_time) = month(curdate()) AND (time(moderate_time) >= (curtime() - 15));";
    conn.query(querySelectLast15Secon, function (err, rows, fields) {
      if (err) throw err;
      callback(rows);
      conn.release();
    })
  });
};

我在进行调试之前使用console.dir(conn.threadId)进行调试,然后打印出来,那是什么意思? (每个行中的数字)

i used console.dir(conn.threadId) before a code to debug, and it printed like that, so what is that mean? (each number in lines)

6177 6180 6181 6184 6183 6185 6176 6178 6179 6179 6177 6183 6184 6185 6182 6180 6177 6176 6181 6183

6177 6180 6181 6184 6183 6185 6176 6178 6179 6177 6183 6184 6185 6182 6180 6177 6176 6181 6183

推荐答案

已修复! 问题出在express-sql-session!我从代码中删除了它,并且效果很好.所以我认为我需要在这里为他们报告这个问题:

Fixed! The problem is from express-sql-session! I removed it from the code and its works fine. So i think i need to report this problems for them in here:

https://github.com/chill117/express-mysql-session/issues

我认为该模块中的connection.end()存在一些问题.不知道在哪里,但也许应该花点时间找出答案.

I think there is some issue with connection.end() in that module. Dont know where but maybe should take a time to find it out.

这篇关于NodeJS在Mac上运行,在centOS上部署时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆