Saturday 24 June 2017

I am a web dev noob deploying Node.js, express, knex app on Heroku - my app is uploaded and database is set up but I can't seem to config knex properly to have my heroku app make queries to database? Any help appreciated

Hi all! Super big noob here only started coding 4 weeks ago so I apologize if this question is incredibly ignorant. I am deploying this small node.js express and knex web app on Heroku, everything runs well locally. So far I have created the app successfully from the commandline, all the pages render. I have created the postgresql database on heroku, i have successfully done migrations so my tables are all set up but when i try to submit a form which is suppose to insert data into the database I keep getting this error in the logs:2017-06-25T06:01:57.360120+00:00 app[web.1]: Unhandled rejection Error: Pool is destroyed 2017-06-25T06:01:57.360123+00:00 app[web.1]: at Pool.acquire (/app/node_modules/pool2/lib/pool.js:162:12) 2017-06-25T06:01:57.360124+00:00 app[web.1]: at /app/node_modules/knex/lib/client.js:268:29 2017-06-25T06:01:57.360125+00:00 app[web.1]: at Promise._execute (/app/node_modules/bluebird/js/release/debuggability.js:300:9) 2017-06-25T06:01:57.360125+00:00 app[web.1]: at Promise._resolveFromExecutor (/app/node_modules/bluebird/js/release/promise.js:483:18) 2017-06-25T06:01:57.360126+00:00 app[web.1]: at new Promise (/app/node_modules/bluebird/js/release/promise.js:79:10) 2017-06-25T06:01:57.360127+00:00 app[web.1]: at Client.acquireConnection (/app/node_modules/knex/lib/client.js:264:21) 2017-06-25T06:01:57.360131+00:00 app[web.1]: at /app/node_modules/knex/lib/runner.js:188:47 2017-06-25T06:01:57.360132+00:00 app[web.1]: at Promise._execute (/app/node_modules/bluebird/js/release/debuggability.js:300:9) 2017-06-25T06:01:57.360134+00:00 app[web.1]: at /app/node_modules/knex/lib/runner.js:187:35 2017-06-25T06:01:57.360133+00:00 app[web.1]: at new Promise (/app/node_modules/bluebird/js/release/promise.js:79:10) 2017-06-25T06:01:57.360135+00:00 app[web.1]: at Function.Promise.attempt.Promise.try (/app/node_modules/bluebird/js/release/method.js:39:29) 2017-06-25T06:01:57.360132+00:00 app[web.1]: at Promise._resolveFromExecutor (/app/node_modules/bluebird/js/release/promise.js:483:18) 2017-06-25T06:01:57.360134+00:00 app[web.1]: at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23) 2017-06-25T06:01:57.360136+00:00 app[web.1]: at Runner.run (/app/node_modules/knex/lib/runner.js:41:44) 2017-06-25T06:01:57.360136+00:00 app[web.1]: at Runner.ensureConnection (/app/node_modules/knex/lib/runner.js:186:39) 2017-06-25T06:01:57.360137+00:00 app[web.1]: at QueryBuilder.Target.then (/app/node_modules/knex/lib/interface.js:32:43)Any help at all is appreciated, I've gone through the tutorial on heroku and read through their node stuff. I don't have a Procfile set up because as I understand from my reading it's not necessary. Here is my Knex config: production: { client: 'pg', connection: process.env.DATABASE_URL + '?ssl=true', debug: true, pool: { min: 2, max: 10 }, migrations: { directory: './db/migrations', tableName: 'migrations' } } Here is my server.js:"use strict"; if (process.env.NODE_ENV !== 'production') require('dotenv').config(); const PORT = process.env.PORT || 8080; const ENV = process.env.ENV || "development"; const express = require("express"); const bodyParser = require("body-parser"); const sass = require("node-sass-middleware"); const app = express(); var pg = require('pg'); const knexConfig = require("./knexfile"); const knex = require("knex")(knexConfig[ENV]); const morgan = require('morgan'); const knexLogger = require('knex-logger'); // Seperated Routes for each Resource const pollRoutes = require("./routes/poll"); const voteRoutes = require("./routes/vote"); const administrativeRoutes = require("./routes/administrative"); const dbHelper = require("./lib/dbHelper")(knex); app.use(morgan('dev')); app.use(knexLogger(knex)); app.set("view engine", "ejs"); app.use(bodyParser.urlencoded({ extended: true })); app.use("/styles", sass({ src: __dirname + "/styles", dest: __dirname + "/public/styles", debug: true, outputStyle: 'expanded' })); app.use(express.static("public")); app.get("/", (req, res) => { res.redirect("/create"); }); app.get("/error", (req, res) => { res.render('error'); }); // Mount all resource routes app.use("/create", pollRoutes(dbHelper, process.env)); app.use("/vote", voteRoutes(dbHelper, process.env)); app.use("/administrative", administrativeRoutes(dbHelper)); // Home page app.listen(PORT, () => { console.log("Example app listening on port " + PORT); }); Again, any help is much appreciated. I used to work as an illustrator before I began learning this stuff, I'm happy to draw a portrait for whoever helps me solves this problem <3

Submitted June 25, 2017 at 07:15AM by derkynord

No comments:

Post a Comment