Giter Site home page Giter Site logo

fly-deployment-demo's Introduction

Deploying an Express/Postgres app to Fly.io

1. Setting up the node app

This part was simple. We just followed this guide to clone and deploy a demo app that was provided for us by fly. The first time you do this, you have to set up your account and add a credit card.

2. Creating the local Postgres database

You can use psql to create a new database that your local application will connect to. Once it's connected, you should connect to it in your code with a connection string. Make sure the connection string is set to a DATABASE_URL env var in your .env file.

DATABASE_URL='postgres://localhost:5432/your_db_name'

3. Install node-pg-migrate and create migrations

Now that your database is set up, you want to update the schema to support your apps functionality. To do this, we'll use migrations.

Check out the docs and look at the package.json file and db/migrations directory in this repo for inspiration.

Once you've run your migraton to create a table, you can use psql to add some data to it for testing purposes.

4. Update your server code to query your database.

You can checkout the server.js file in this repo for ideas.

Make sure it's all working locally!

5. Create your database on fly.

docs

fly postgres create

6. Attach your fly db to your express app.

docs

fly postgres attach --app <app-name> <postgres-app-name>

This sets the DATABASE_URL env var on your express app so the server code you've written can connect to postgres without an additional configuration.

7. Make sure migrations run as part of the deploy process.

To do this, you need to add the following to your fly.toml

[deploy]
  release_command = "npm run migrate up"

(Assuming you've defined a migrate script in your package.json file.)

8. Deploy!

9. Keep developing your application

Now that your fly infrastructure is set up, all you have to is remember to make all database schema changes with migrations, and then deploy as you normally would! ๐Ÿฅณ

fly-deployment-demo's People

Contributors

codepope avatar parisyee avatar

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.