0

My Web site that using PostgreSQL not working on Heroku.

It's working at my PC own(ex.npm start = node index.js).

But on Heroku, it's not working.

It's my code.

function dbconnect(params, groupFlg) {
return new Promise(function(resolve, reject){
    const pool = pg.Pool(
        {
            connectionString: process.env.DATABASE_URL,
            ssl: true,
        }
    );
    params = params.split(/\s/);
    var queryText = 'SELECT * FROM movies WHERE (movieperson LIKE '%test%' OR movietitle LIKE '%test%') ORDER BY movieid DESC;';
    var query = {
        text: queryText
    };
    console.log("query: " + query.text);
    pool.connect(function (err, client, done) {
        if (err) {
            console.error(err.stack);
        } else {
            console.log("else 132");
            client.query(query.text)
                .then(res => {
                    done();
                    var resultHTML = "";
                    for (let i = 0; i < res.rows.length; i++) {
                        resultHTML += makeHTML(res.rows[i]);
                    }
                    resArray = res.rows;
                    client.end();
                    if (resultHTML == "") {
                        resultHTML = "not looking";
                    }
                    resolve(resultHTML);
                })
                .catch(e => console.error(e.stack));
        }
    });
    pool.end();
});
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    What's the error? Which Postgres add-on did you use? What are the tables on the database? – Tin Nguyen Feb 10 '21 at 09:31
  • Error is just at=error code=H12 desc="Request timeout". I use Heroku Postgres add-on. The table has columns movieid, movieperson, movietitle. – Akiyuri Feb 10 '21 at 09:39
  • Have you connected to the DB manually and checked the tables? Also your comment isn't really satisfying. Provide more and precise information. – Tin Nguyen Feb 10 '21 at 12:16
  • If t's working at your PC maybe is the engine of node. see this [thread](https://stackoverflow.com/questions/66073991/heroku-h12-request-timeout-error-on-using-db-query-method-node-js/66138573#66138573) – Santiago Garcia Gil Feb 11 '21 at 13:37
  • @Santiago Garcia Gil Thank you! I success. – Akiyuri Feb 12 '21 at 17:09

0 Answers0