将rds上的postgresql连接到节点js服务器

时间:2015-03-07 02:26:49

标签: node.js postgresql amazon-web-services amazon-ec2 amazon-rds

我试图使用我的节点js服务器直接连接到我在AWS上的RDS实例(我的节点js服务器在ec2实例上运行)上的postgres数据库。我很难找到真正连接它的东西。现在它一直在打破我。

Here is my error: 

events.js:72
        throw er; // Unhandled 'error' event
              ^
error: there is no parameter $0
    at Connection.parseE (/home/ec2-user/Outfitr/Server/node_modules/pg/lib/connection.js:534:11)
    at Connection.parseMessage (/home/ec2-user/Outfitr/Server/node_modules/pg/lib/connection.js:361:17)
    at Socket.<anonymous> (/home/ec2-user/Outfitr/Server/node_modules/pg/lib/connection.js:105:22)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:765:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    at emitReadable (_stream_readable.js:423:5)
    at readableAddChunk (_stream_readable.js:166:9)
    at Socket.Readable.push (_stream_readable.js:128:10)

这是我的代码尝试连接所有内容(使用一些更无关紧要的代码):

var AWS = require('aws-sdk')
var pg = require("pg")
var express = require("express")
var app = express();
var gm = require("gm");
var fs = require("fs");
var async = require("async");
var bodyParser = require('body-parser');



var conString = "pg://MyDBUser:MyDBPassword@mydb.cdqciw4zlodp.us-west-2.rds.amazonaws.com:5432/MyDB";


//var client = new pg.Client(conString);
//client.connect();


//var Client = require('pg-native')

var client = new pg.Client(conString);
//client.connect();
client.connect(function(err) {
 if(err) throw err
     console.log('connected!')
})

//var pg = require( 'pg' ).native;

function create_user(username, password, firstname, lastname, gender, latitude, longitude,
  description, city, state_province, country, email, phone_number) {

  process.stdout.write("well we got here")

  pg.connect( conString, function( err,client) {

      client.query("INSERT INTO App_User(username, password, firstname, lastname, gender, latitude, longitude, description, city, state_province, country, email, phone_number) VALUES ($0,$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)", [username, password, firstname, lastname, gender, latitude, longitude,
      description, city, state_province, country, email, phone_number]);

      });
}

0 个答案:

没有答案