Git Product home page Git Product logo

deployingtoherokuwithpostgresqlandknex's Introduction

Deploying to Heroku with Postgresql and Knex

Fork and clone

  • Install dependencies:
$ cd deployingToHerokuWithPostgresqlAndKnex
$ npm install
$ createdb knex-heroku
$ touch .env
  • Run the migration and seed files locally:
$ knex migrate:latest --env production
$ knex seed:run --env production

  • Confirm thats all working by running nodemon and checking if 3 amphibians are rendered at localhost:3000

Setting up for Heroku

  • Require the dotenv module at the top of your knexfile.js
require('dotenv').load();

module.exports = {

  production: {
    client: 'postgresql',
    connection: 'postgres://localhost/knex-heroku',
    pool : {
      min: 2,
      max: 10
    }
  }
};
  • Now add the connection from your knexfile.js to your .env file as an environment variable called DATABASE_URL
//in the .env file
DATABASE_URL=postgres://localhost/knex-heroku
  • Now you'll need to change your connection in your knexfile.js to use the environment variable
//knexfile.js
require('dotenv').load();

module.exports = {

  production: {
    client: 'postgresql',
    connection: process.env.DATABASE_URL,
    pool : {
      min: 2,
      max: 10
    }
  }
};

  • Good, now your database connection will be able to use either your local environment variable or the upcoming heroku database environment variable

  • Create a heroku app in the root directory of this exercise

$ heroku create
  • Setup a remote heroku postgresql database with the free hobby-dev package
$ heroku addons:create heroku-postgresql:hobby-dev
  • Push up your code to heroku
$ git add -A
$ git commit -m"ready for heroku"
$ git push heroku master
  • Now run your migrations and your seeds via heroku
$ heroku run knex migrate:latest
$ heroku run knex seed:run
  • Check your results
$ heroku open
  • Congrats you have a remote heroku database !

STRETCH GOAL

  • Get together with your team and deploy the application you made at Fridays Hackathon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.