Nella mia app Node.js, sto cercando di connettermi a un database MySQL ospitato su Amazon.Errore nella libreria MySQL per Node.js
$ npm install mysql
Il mio codice simile a questa:
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();
posso collegarmi al mio DB MySQL utilizzando Workbench - quindi, sono abbastanza sicuro che le mie credenziali sono a posto.
Quando tento di collegarmi ricevo il seguente errore:
Connection.js:91 Uncaught TypeError: Net.createConnection is not a function
Debug del codice dalla libreria NPM - questo è dove l'errore è gettato in connection.js
:
this._socket = (this.config.socketPath)
? Net.createConnection(this.config.socketPath)
: Net.createConnection(this.config.port, this.config.host);
Il connection.js
ha una dipendenza:
var Net = require('net');
Sto eseguendo Node.js localmente sul mio computer Windows.
Qualcuno può dirmi cosa potrebbe causare questo errore?
creato un biglietto separato: Error thrown calling Node.js net.createConnection
[Potrebbe essere utile] (https://github.com/mysqljs/mysql/issues/491) –
Come hai eseguito il debug e trovato una causa sottostante è possibile che potrebbe esserci un problema con il nodo versione .js. Quale versione del nodo stai usando esattamente? –
Il mio nodo è la versione 4.2.3 – user1526912