# Deployment
Let's deploy the todo app to Heroku (opens new window).
# Connect to Heroku Postgres
Modify the highlighted code in the api server module to only use Postgres
in production, and keep using the simple JSON db in our dev environment.
src/server/api.ts
//...
export const api = createRemultServer({
//...
dataProvider: process.env["NODE_ENV"] === "production" ?
createPostgresConnection({
configuration: "heroku"
}) : undefined,
//...
});
The { configuration: "heroku" }
argument passed to Remult's createPostgresConnection()
tells Remult to use the DATABASE_URL
environment variable as the connectionString
for Postgres. (See Heroku documentation (opens new window).)
In development, the dataProvider
function returns undefined
, causing Remult to continue to use the default JSON-file database.
# Deploy to Heroku
In order to deploy the todo app to heroku (opens new window) you'll need a heroku
account. You'll also need Git (opens new window) and Heroku CLI (opens new window) installed.
- Modify the project's
start
npm script to bind the$PORT
to the port assigned by heroku.
package.json
"start": "next start -p $PORT"
- Create a Heroku
app
.
heroku create
- Set the jwt authentication to something random - you can use an online UUID generator (opens new window).
heroku config:set NEXTAUTH_SECRET=random-secret
- Provision a dev postgres database on Heroku.
heroku addons:create heroku-postgresql:hobby-dev
- Commit the changes to git and deploy to Heroku using
git push
.
git add .
git commit -m "todo app tutorial"
git push heroku main
- Open the deployed app using
heroku apps:open
command.
heroku apps:open
Note
If you run into trouble deploying the app to Heroku, try using Heroku's documentation (opens new window).
That's it - our application is deployed to production, play with it and enjoy.
To see a larger more complex code base, visit our CRM example project (opens new window)
Love Remult? Give our repo a star.⭐
← Database