【发布时间】:2016-10-26 15:14:05
【问题描述】:
在我的 Node.js 应用程序中,我正在尝试连接到托管在 Amazon 上的 MySQL 数据库。
$ npm install mysql
我的代码如下所示:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'my amazon sql db',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
我可以使用 Workbench 连接到我的 MySQL 数据库——因此,我很确定我的凭据没有问题。
当我尝试连接时,出现以下错误:
Connection.js:91 Uncaught TypeError: Net.createConnection is not a function
从 npm 库中调试代码——这是在 connection.js 中引发错误的地方:
this._socket = (this.config.socketPath)
? Net.createConnection(this.config.socketPath)
: Net.createConnection(this.config.port, this.config.host);
connection.js 有一个依赖项:
var Net = require('net');
我在我的 Windows 计算机上本地运行 Node.js。
谁能告诉我是什么导致了这个错误?
创建了一个单独的票: Error thrown calling Node.js net.createConnection
【问题讨论】:
-
当您调试它并找到根本原因时,node.js 版本可能存在问题。您使用的是哪个节点版本?
-
我的节点是4.2.3版
-
可能是您的亚马逊凭证吗?某处?虽然不确定
-
它不是亚马逊凭证。错误表示找不到net.connection方法