mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-25 02:08:06 +02:00
Signed-off-by: Utkarsh Mathur <78642104+MathurUtkarsh@users.noreply.github.com> Signed-off-by: Utkarsh Mathur <utkarshmathur05@gmail.com> |
||
---|---|---|
.. | ||
nodejs | ||
postgres | ||
docker-compose.yml | ||
README.md |
##NodeJS with Postgres Connection
This is a sample project that demonstrates how to connect a NodeJS app using Express to a Postgres database using Docker Compose. The project includes the following components:
- NodeJS app using Express
- Postgres database
- Docker Compose file to set up the environment
##Project Structure The project consists of the following files:
- docker-compose.yml: The Docker Compose file that defines the services for the NodeJS app and Postgres database, and the network connections between them.
- nodejs directory: Contains the NodeJS code, including index.js and Dockerfile for building the NodeJS app image.
- postgres directory: Contains the Dockerfile for building the Postgres database image.
##Getting Started To run this project, follow these steps:
- Clone the repository.
- From the root of the directory, run docker-compose up to start the environment.
- The NodeJS app will be available at http://localhost:3000 and the Postgres database can be accessed at postgres://myuser:mypassword@localhost:5432/mydb. Expected Results When you access the NodeJS app at http://localhost:3000, you should see the message "Hello World!" displayed in the browser.
##Conclusion This project provides a simple example of how to connect a NodeJS app to a Postgres database using Docker Compose. The project structure follows a standard naming convention and separates the code for the two services into separate directories. By using Docker Compose, it's easy to set up a development environment that can be used to test and debug your NodeJS and Postgres applications.