vendredi 6 mars 2015

connecting postgresql on rds to node js server

I'm trying to use my node js server to connect directly to my postgres database I have on an RDS instance(my node js server is running on an ec2 instance) on AWS. I am having a hard time finding something that actually connects it. Right now it keeps breaking on me.



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)


And here is my code that is trying to connect everything (with some of the more irrelevent code taken out):



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]);

});
}




Aucun commentaire:

Enregistrer un commentaire