This sample project demonstrates how to deploy a full-stack application using React for the frontend, Node.js for the backend, and PostgreSQL for the database.
In production, the Node.js server also serves the built React app, so one service handles both the UI and the API. The database is a Defang managed Postgres instance.
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider 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 --buildOr run without using Docker by doing the following:
- run
npm installto install the nodejs dependencies in both theclientdirectory and theserverdirectory - create or modify the .env file in both the
clientdirectory and theserverdirectory with localhost, or create a .env.local to override the .env file. - run
npm start
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.
The password for the Postgres database.
defang config set POSTGRES_PASSWORDThe server connects to Postgres over SSL, as Defang managed Postgres requires. If you deploy to the Playground, where Postgres runs as a plain container, set POSTGRES_SSL=false on the app service.
Note
Download Defang CLI
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose upIf you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js & React & PostgreSQL
Short Description: A full-stack to-do list application.
Tags: Node.js, React, Full-stack, PostgreSQL, JavaScript, SQL, sample
Languages: nodejs