The error from executing your query means that r
is not getting populated correctly. It's worth being explicit about user input so your system doesn't raise an error downstream (in the query) rather than at the problem root:
app.post('/newcause', function (req,res){
console.log(req.body);
var g;
var r = [];
r.push(req.body.causename, req.body.Goal, req.body.Organization, req.body.sponsor, req.body.submitterEmail);
client = pg.connect(connectionString, function(err, client, done){
if(err) console.log(err);
client.query('INSERT INTO causes (cause_name, goal, organization, sponsor, submitter) VALUES ($1,$2,$3,$4,$5)', r, function(err){
console.log('This is r' + r.toString())
if (err) console.log(err);
});
});
});
It's also worth mentioning that it might be a good idea to standardize your variable name-casing in the post submission.