This is a sample Next.js application that uses Postgres as a database. It is a simple example that demonstrates how to connect to a Postgres database from a Next.js application: on each request it takes the user's IP address, geo-locates it, and stores the result in the database, then displays the last 20 results on the home page.
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
A password that will be used to connect to the Postgres database.
- Open the terminal and type
defang login
- Use the
defang config
command to setup environment variables. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Next.js & Postgres
Short Description: A sample Next.js application that uses Postgres as a database.
Tags: Next.js, Postgres, Database, Node.js
Languages: TypeScript, JavaScript