Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to use a heroku database (already deployed in heroku) for my AngularJS application created using Yeoman. I want to persist my data that is currently an array of JSON objects that goes away when I refresh the page. I am trying to follow Heroku's guide for Node.js here (https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js) but it is very shot, no examples, and I am fairly new to servers/databases. I have a 'web.js' file and the Procfile int my root directories for Node.js and heroku to read that file. I have the "dependencies" already set but I am not sure what is happening in this code below that heroku provides

  var pg = require('pg');
  pg.connect(process.env.DATABASE_URL, function(err, client) {
     var query = client.query('SELECT * FROM your_table');

     query.on('row', function(row) {
          console.log(JSON.stringify(row));
     });
   });

First: Where do I put this code?

Second: What is happening here?

and Third: How do I use it to upload my data that is currently an array of JSON objects that I hardcode into my code into the heroku database?


My web.js file

var gzippo = require('gzippo');
var express = require('express');
var app = express();

app.use(express.logger('dev'));
app.use(gzippo.staticGzip("" + MyApp + "/dist"));
app.listen(process.env.PORT || 9000);

My Procfile

web: node web.js
share|improve this question

1 Answer 1

That code goes in your web.js file.

I'm pretty sure it's accessing your database and setting the results to the variable query so you can access the data.

I think want you want for pushing the data is to look here, particularly at pg:push.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.