Hi there,
I am doing my first node project and want to save subscriber input info to
a postgres db, and I think I almost have it working. It successfully made
the table when I tested it in my browser, but instead of saving the data,
like it should, it is ignoring the data altogether and killing my server. I
am doing this project to understand the internals and how all the moving
parts work together, so I would appreciate any insights you guys would be
willing to share.
I have this code in my db.js file:
exports.subscribe = function (name, email) {
> connectUser();
> client.query("INSERT INTO subscriber (name, email) values($1, $2)",
> [name, email]);
> }
>
exports.connectUser = pg.connect(conString, function(err, client, done) {
>
if(err) {
> return console.error('error fetching client from pool', err);
> }
> client.query('CREATE TABLE IF NOT EXISTS subscriber (name varchar(64),
> email varchar(64))', function(err, result) {
> done();
> if(err) {
> return console.error('error running query', err);
> }
> console.log(result.rows);
> });
> });
and it is getting called here in my index.db file:
function addNewPost(request, response) {
> var postsHTML = fs.readFileSync('views/post/posts.html');
> response.writeHead(200, {
> 'content-type': 'text/html; charset=utf-8'
> });
> parseBody(request, function(body) {
> db.connectUser();
> db.subscribe(body.name, body.email);
> });
> response.end(postsHTML);
> }
My server works fine when I comment out those two db statements. The app is
running on localhost:3000 and the db on localhost:5432. Please ask me if I
am not providing enough information. Thanks in advance!
K
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/64430273-9418-4098-8bf2-a72bae248184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.