├── .env ├── README.md ├── bezkoder-app ├── .env.sample ├── Dockerfile ├── README.md ├── app │ ├── config │ │ └── db.config.js │ ├── controllers │ │ └── tutorial.controller.js │ ├── models │ │ ├── index.js │ │ └── tutorial.model.js │ └── routes │ │ └── turorial.routes.js ├── package.json └── server.js └── docker-compose.yml /.env: -------------------------------------------------------------------------------- 1 | POSTGRESDB_USER=postgres 2 | POSTGRESDB_ROOT_PASSWORD=123456 3 | POSTGRESDB_DATABASE=bezkoder_db 4 | POSTGRESDB_LOCAL_PORT=5433 5 | POSTGRESDB_DOCKER_PORT=5432 6 | 7 | NODE_LOCAL_PORT=6868 8 | NODE_DOCKER_PORT=8080 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Compose Nodejs and Postgres example 2 | 3 | ## Run the System 4 | We can easily run the whole with only a single command: 5 | ```bash 6 | docker compose up 7 | ``` 8 | 9 | Docker will pull the Postgres and Node.js images (if our machine does not have it before). 10 | 11 | The services can be run on the background with command: 12 | ```bash 13 | docker compose up -d 14 | ``` 15 | 16 | ## Stop the System 17 | Stopping all the running containers is also simple with a single command: 18 | ```bash 19 | docker compose down 20 | ``` 21 | 22 | If you need to stop and remove all containers, networks, and all images used by any service in docker-compose.yml file, use the command: 23 | ```bash 24 | docker compose down --rmi all 25 | ``` 26 | 27 | For more detail, please visit: 28 | > [Docker Compose Node.js and Postgres example](https://www.bezkoder.com/docker-compose-nodejs-postgres/) 29 | 30 | Related Posts: 31 | > [Node.js, Express & PostgreSQL: CRUD Rest Api example](https://www.bezkoder.com/node-express-sequelize-postgresql/) 32 | 33 | > [Node.js Express Pagination with PostgreSQL example](https://www.bezkoder.com/node-js-pagination-postgresql/) 34 | 35 | > [Import CSV data into PostgreSQL using Node.js](https://www.bezkoder.com/node-js-csv-postgresql/) 36 | 37 | > [Export PostgreSQL data to CSV file using Node.js](https://www.bezkoder.com/node-js-export-postgresql-csv-file/) 38 | 39 | > [Node.js JWT Authentication & Authorization with PostgreSQL example](https://www.bezkoder.com/node-js-jwt-authentication-postgresql/) 40 | 41 | Associations: 42 | > [Sequelize Associations: One-to-Many Relationship example](https://bezkoder.com/sequelize-associate-one-to-many/) 43 | 44 | > [Sequelize Associations: Many-to-Many Relationship example](https://bezkoder.com/sequelize-associate-many-to-many/) 45 | -------------------------------------------------------------------------------- /bezkoder-app/.env.sample: -------------------------------------------------------------------------------- 1 | DB_HOST=localhost 2 | DB_USER=postgres 3 | DB_PASSWORD=123456 4 | DB_NAME=bezkoder_db 5 | DB_PORT=5432 6 | 7 | NODE_DOCKER_PORT=8080 -------------------------------------------------------------------------------- /bezkoder-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14 2 | 3 | WORKDIR /bezkoder-app 4 | COPY package.json . 5 | RUN npm install 6 | COPY . . 7 | CMD npm start -------------------------------------------------------------------------------- /bezkoder-app/README.md: -------------------------------------------------------------------------------- 1 | # Node.js PostgreSQL CRUD example with Express Rest APIs 2 | 3 | Full Article with implementation: 4 | > [Node.js PostgreSQL CRUD example with Express Rest APIs](https://www.bezkoder.com/node-express-sequelize-postgresql/) 5 | 6 | We will build Rest Apis that can create, retrieve, update, delete and find Tutorials by title. 7 | 8 | The following table shows overview of the Rest APIs that will be exported: 9 | 10 | - GET `api/tutorials` get all Tutorials 11 | - GET `api/tutorials/:id` get Tutorial by id 12 | - POST `api/tutorials` add new Tutorial 13 | - PUT `api/tutorials/:id` update Tutorial by id 14 | - DELETE `api/tutorials/:id` remove Tutorial by id 15 | - DELETE `api/tutorials` remove all Tutorials 16 | - GET `api/tutorials/published` find all published Tutorials 17 | - GET `api/tutorials?title=[kw]` find all Tutorials which title contains 'kw' 18 | 19 | Front-end that works well with this Back-end 20 | > [Axios Client](https://www.bezkoder.com/axios-request/) 21 | 22 | > [Angular 8](https://www.bezkoder.com/angular-crud-app/) / [Angular 10](https://www.bezkoder.com/angular-10-crud-app/) / [Angular 11](https://www.bezkoder.com/angular-11-crud-app/) / [Angular 12](https://www.bezkoder.com/angular-12-crud-app/) / [Angular 13](https://www.bezkoder.com/angular-13-crud-example/) / [Angular 14](https://www.bezkoder.com/angular-14-crud-example/) / [Angular 15](https://www.bezkoder.com/angular-15-crud-example/) / [Angular 16](https://www.bezkoder.com/angular-16-crud-example/) 23 | 24 | > [Vue 2 Client](https://www.bezkoder.com/vue-js-crud-app/) / [Vue 3 Client](https://www.bezkoder.com/vue-3-crud/) / [Vuetify Client](https://www.bezkoder.com/vuetify-data-table-example/) 25 | 26 | > [React Client](https://www.bezkoder.com/react-crud-web-api/) / [React Redux Client](https://www.bezkoder.com/react-redux-crud-example/) 27 | 28 | ## Demo Video 29 | This is our Node.js PostgreSQL CRUD example using Express & Sequelize application demo, test Rest Apis with Postman. 30 | 31 | [![Node.js PostgreSQL CRUD example Github](http://img.youtube.com/vi/x1pZHN_sjGk/0.jpg)](http://www.youtube.com/watch?v=x1pZHN_sjGk "Node.js PostgreSQL CRUD example Github") 32 | 33 | ### Test the APIs 34 | Run our Node.js application with command: `node server.js`. 35 | 36 | Using Postman, we're gonna test all the Apis above. 37 | 38 | - Create a new Tutorial using `POST /tutorials` Api 39 | 40 | ![node-js-postgresql-crud-example-create](https://dev-to-uploads.s3.amazonaws.com/i/hqvz8ra9p21z927iwzph.png) 41 | 42 | After creating some new Tutorials, you can check PostgreSQL table: 43 | ```testdb=# select * from tutorials; 44 | id | title | description | published | createdAt | updatedAt 45 | ----+-------------+-------------------+-----------+----------------------------+---------------------------- 46 | 1 | Node Tut #1 | Tut#1 Description | f | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07 47 | 2 | Node Tut #2 | Tut#2 Description | f | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:43:05.131+07 48 | 3 | Node Tut #3 | Tut#3 Description | f | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07 49 | 4 | Js Tut #4 | Tut#4 Desc | f | 2020-01-29 10:45:40.016+07 | 2020-01-29 10:45:40.016+07 50 | 5 | Js Tut #5 | Tut#5 Desc | f | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:45:44.289+07 51 | ``` 52 | 53 | - Retrieve all Tutorials using `GET /tutorials` Api 54 | 55 | ![node-js-postgresql-crud-example-retrieve-all](https://dev-to-uploads.s3.amazonaws.com/i/m9razjm1njgww58er3as.png) 56 | 57 | - Retrieve a single Tutorial by id using `GET /tutorials/:id` Api 58 | 59 | ![node-js-postgresql-crud-example-retrieve-one](https://dev-to-uploads.s3.amazonaws.com/i/0kuojvc596i5u423od2b.png) 60 | 61 | - Update a Tutorial using `PUT /tutorials/:id` Api 62 | 63 | ![node-js-postgresql-crud-example-update](https://dev-to-uploads.s3.amazonaws.com/i/3buqfz0by0lu2z4kf3uq.png) 64 | 65 | Check `tutorials` table after some rows were updated: 66 | ```testdb=# select * from tutorials; 67 | id | title | description | published | createdAt | updatedAt 68 | ----+----------------+-------------------+-----------+----------------------------+---------------------------- 69 | 1 | Node Tut #1 | Tut#1 Description | f | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07 70 | 3 | Node Tut #3 | Tut#3 Description | f | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07 71 | 2 | Node Js Tut #2 | Tut#2 Description | t | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:51:55.235+07 72 | 4 | Js Tut #4 | Tut#4 Desc | t | 2020-01-29 10:45:40.016+07 | 2020-01-29 10:54:17.468+07 73 | 5 | Js Tut #5 | Tut#5 Desc | t | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:54:20.544+07 74 | ``` 75 | 76 | - Find all Tutorials which title contains 'js': `GET /tutorials?title=js` 77 | 78 | ![node-js-postgresql-crud-example-search](https://dev-to-uploads.s3.amazonaws.com/i/u2hbmz5r35o7uo09y3z5.png) 79 | 80 | - Find all published Tutorials using `GET /tutorials/published` Api 81 | 82 | ![node-js-postgresql-crud-example-search-status](https://dev-to-uploads.s3.amazonaws.com/i/dbo753wfqibt0b93d82d.png) 83 | 84 | - Delete a Tutorial using `DELETE /tutorials/:id` Api 85 | 86 | ![node-js-postgresql-crud-example-delete-one](https://dev-to-uploads.s3.amazonaws.com/i/pyos3wq4tchb8ixuyj1c.png) 87 | 88 | Tutorial with id=4 was removed from `tutorials` table: 89 | ```testdb=# select * from tutorials; 90 | id | title | description | published | createdAt | updatedAt 91 | ----+----------------+-------------------+-----------+----------------------------+---------------------------- 92 | 1 | Node Tut #1 | Tut#1 Description | f | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07 93 | 3 | Node Tut #3 | Tut#3 Description | f | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07 94 | 2 | Node Js Tut #2 | Tut#2 Description | t | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:51:55.235+07 95 | 5 | Js Tut #5 | Tut#5 Desc | t | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:54:20.544+07 96 | ``` 97 | 98 | - Delete all Tutorials using `DELETE /tutorials` Api 99 | 100 | ![node-js-postgresql-crud-example-delete-all](https://dev-to-uploads.s3.amazonaws.com/i/ga42747jorssl20ywyug.png) 101 | 102 | Now there are no rows in `tutorials` table: 103 | ```testdb=# select * from tutorials; 104 | id | title | description | published | createdAt | updatedAt 105 | ----+-------+-------------+-----------+-----------+----------- 106 | ``` 107 | 108 | For more detail, please visit: 109 | > [Node.js PostgreSQL CRUD example with Express Rest APIs](https://www.bezkoder.com/node-express-sequelize-postgresql/) 110 | 111 | > [Node.js Express Pagination with PostgreSQL example](https://www.bezkoder.com/node-js-pagination-postgresql/) 112 | 113 | Security: 114 | > [Node.js JWT Authentication & Authorization with PostgreSQL example](https://www.bezkoder.com/node-js-jwt-authentication-postgresql/) 115 | 116 | Associations: 117 | > [Sequelize Associations: One-to-Many Relationship example](https://www.bezkoder.com/sequelize-associate-one-to-many/) 118 | 119 | > [Sequelize Associations: Many-to-Many Relationship example](https://www.bezkoder.com/sequelize-associate-many-to-many/) 120 | 121 | Fullstack: 122 | > [Vue + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/vue-node-express-postgresql/) 123 | 124 | > [React + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/react-node-express-postgresql/) 125 | 126 | > [Angular 8 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-node-express-postgresql/) 127 | 128 | > [Angular 10 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-10-node-express-postgresql/) 129 | 130 | > [Angular 11 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-11-node-js-express-postgresql/) 131 | 132 | > [Angular 12 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-12-node-js-express-postgresql/) 133 | 134 | > [Angular 13 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-13-node-js-express-postgresql/) 135 | 136 | > [Angular 14 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-14-node-js-express-postgresql/) 137 | 138 | > [Angular 15 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-15-node-js-express-postgresql/) 139 | 140 | > [Angular 16 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-16-node-js-express-postgresql/) 141 | 142 | Integration (run back-end & front-end on same server/port): 143 | > [Integrate React with Node.js Restful Services](https://www.bezkoder.com/integrate-react-express-same-server-port/) 144 | 145 | > [Integrate Angular with Node.js Restful Services](https://www.bezkoder.com/integrate-angular-12-node-js/) 146 | 147 | > [Integrate Vue with Node.js Restful Services](https://www.bezkoder.com/serve-vue-app-express/) 148 | 149 | ## Project setup 150 | ``` 151 | npm install 152 | ``` 153 | 154 | ### Run 155 | ``` 156 | node server.js 157 | ``` 158 | -------------------------------------------------------------------------------- /bezkoder-app/app/config/db.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | HOST: process.env.DB_HOST, 3 | USER: process.env.DB_USER, 4 | PASSWORD: process.env.DB_PASSWORD, 5 | DB: process.env.DB_NAME, 6 | port: process.env.DB_PORT, 7 | dialect: "postgres", 8 | pool: { 9 | max: 5, 10 | min: 0, 11 | acquire: 30000, 12 | idle: 10000 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /bezkoder-app/app/controllers/tutorial.controller.js: -------------------------------------------------------------------------------- 1 | const db = require("../models"); 2 | const Tutorial = db.tutorials; 3 | const Op = db.Sequelize.Op; 4 | 5 | // Create and Save a new Tutorial 6 | exports.create = (req, res) => { 7 | // Validate request 8 | if (!req.body.title) { 9 | res.status(400).send({ 10 | message: "Content can not be empty!" 11 | }); 12 | return; 13 | } 14 | 15 | // Create a Tutorial 16 | const tutorial = { 17 | title: req.body.title, 18 | description: req.body.description, 19 | published: req.body.published ? req.body.published : false 20 | }; 21 | 22 | // Save Tutorial in the database 23 | Tutorial.create(tutorial) 24 | .then(data => { 25 | res.send(data); 26 | }) 27 | .catch(err => { 28 | res.status(500).send({ 29 | message: 30 | err.message || "Some error occurred while creating the Tutorial." 31 | }); 32 | }); 33 | }; 34 | 35 | // Retrieve all Tutorials from the database. 36 | exports.findAll = (req, res) => { 37 | const title = req.query.title; 38 | var condition = title ? { title: { [Op.iLike]: `%${title}%` } } : null; 39 | 40 | Tutorial.findAll({ where: condition }) 41 | .then(data => { 42 | res.send(data); 43 | }) 44 | .catch(err => { 45 | res.status(500).send({ 46 | message: 47 | err.message || "Some error occurred while retrieving tutorials." 48 | }); 49 | }); 50 | }; 51 | 52 | // Find a single Tutorial with an id 53 | exports.findOne = (req, res) => { 54 | const id = req.params.id; 55 | 56 | Tutorial.findByPk(id) 57 | .then(data => { 58 | res.send(data); 59 | }) 60 | .catch(err => { 61 | res.status(500).send({ 62 | message: "Error retrieving Tutorial with id=" + id 63 | }); 64 | }); 65 | }; 66 | 67 | // Update a Tutorial by the id in the request 68 | exports.update = (req, res) => { 69 | const id = req.params.id; 70 | 71 | Tutorial.update(req.body, { 72 | where: { id: id } 73 | }) 74 | .then(num => { 75 | if (num == 1) { 76 | res.send({ 77 | message: "Tutorial was updated successfully." 78 | }); 79 | } else { 80 | res.send({ 81 | message: `Cannot update Tutorial with id=${id}. Maybe Tutorial was not found or req.body is empty!` 82 | }); 83 | } 84 | }) 85 | .catch(err => { 86 | res.status(500).send({ 87 | message: "Error updating Tutorial with id=" + id 88 | }); 89 | }); 90 | }; 91 | 92 | // Delete a Tutorial with the specified id in the request 93 | exports.delete = (req, res) => { 94 | const id = req.params.id; 95 | 96 | Tutorial.destroy({ 97 | where: { id: id } 98 | }) 99 | .then(num => { 100 | if (num == 1) { 101 | res.send({ 102 | message: "Tutorial was deleted successfully!" 103 | }); 104 | } else { 105 | res.send({ 106 | message: `Cannot delete Tutorial with id=${id}. Maybe Tutorial was not found!` 107 | }); 108 | } 109 | }) 110 | .catch(err => { 111 | res.status(500).send({ 112 | message: "Could not delete Tutorial with id=" + id 113 | }); 114 | }); 115 | }; 116 | 117 | // Delete all Tutorials from the database. 118 | exports.deleteAll = (req, res) => { 119 | Tutorial.destroy({ 120 | where: {}, 121 | truncate: false 122 | }) 123 | .then(nums => { 124 | res.send({ message: `${nums} Tutorials were deleted successfully!` }); 125 | }) 126 | .catch(err => { 127 | res.status(500).send({ 128 | message: 129 | err.message || "Some error occurred while removing all tutorials." 130 | }); 131 | }); 132 | }; 133 | 134 | // find all published Tutorial 135 | exports.findAllPublished = (req, res) => { 136 | Tutorial.findAll({ where: { published: true } }) 137 | .then(data => { 138 | res.send(data); 139 | }) 140 | .catch(err => { 141 | res.status(500).send({ 142 | message: 143 | err.message || "Some error occurred while retrieving tutorials." 144 | }); 145 | }); 146 | }; 147 | -------------------------------------------------------------------------------- /bezkoder-app/app/models/index.js: -------------------------------------------------------------------------------- 1 | const dbConfig = require("../config/db.config.js"); 2 | 3 | const Sequelize = require("sequelize"); 4 | const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, { 5 | host: dbConfig.HOST, 6 | dialect: dbConfig.dialect, 7 | 8 | pool: { 9 | max: dbConfig.pool.max, 10 | min: dbConfig.pool.min, 11 | acquire: dbConfig.pool.acquire, 12 | idle: dbConfig.pool.idle 13 | } 14 | }); 15 | 16 | const db = {}; 17 | 18 | db.Sequelize = Sequelize; 19 | db.sequelize = sequelize; 20 | 21 | db.tutorials = require("./tutorial.model.js")(sequelize, Sequelize); 22 | 23 | module.exports = db; 24 | -------------------------------------------------------------------------------- /bezkoder-app/app/models/tutorial.model.js: -------------------------------------------------------------------------------- 1 | module.exports = (sequelize, Sequelize) => { 2 | const Tutorial = sequelize.define("tutorial", { 3 | title: { 4 | type: Sequelize.STRING 5 | }, 6 | description: { 7 | type: Sequelize.STRING 8 | }, 9 | published: { 10 | type: Sequelize.BOOLEAN 11 | } 12 | }); 13 | 14 | return Tutorial; 15 | }; 16 | -------------------------------------------------------------------------------- /bezkoder-app/app/routes/turorial.routes.js: -------------------------------------------------------------------------------- 1 | module.exports = app => { 2 | const tutorials = require("../controllers/tutorial.controller.js"); 3 | 4 | var router = require("express").Router(); 5 | 6 | // Create a new Tutorial 7 | router.post("/", tutorials.create); 8 | 9 | // Retrieve all Tutorials 10 | router.get("/", tutorials.findAll); 11 | 12 | // Retrieve all published Tutorials 13 | router.get("/published", tutorials.findAllPublished); 14 | 15 | // Retrieve a single Tutorial with id 16 | router.get("/:id", tutorials.findOne); 17 | 18 | // Update a Tutorial with id 19 | router.put("/:id", tutorials.update); 20 | 21 | // Delete a Tutorial with id 22 | router.delete("/:id", tutorials.delete); 23 | 24 | // Delete all Tutorials 25 | router.delete("/", tutorials.deleteAll); 26 | 27 | app.use("/api/tutorials", router); 28 | }; 29 | -------------------------------------------------------------------------------- /bezkoder-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-express-sequelize-postgresql", 3 | "version": "1.0.0", 4 | "description": "Node.js Rest Apis with Express, Sequelize & PostgreSQL", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "nodejs", 11 | "express", 12 | "sequelize", 13 | "rest", 14 | "api", 15 | "postgresql" 16 | ], 17 | "author": "bezkoder", 18 | "license": "ISC", 19 | "dependencies": { 20 | "dotenv": "^10.0.0", 21 | "cors": "^2.8.5", 22 | "express": "^4.18.2", 23 | "pg": "^8.11.0", 24 | "pg-hstore": "^2.3.4", 25 | "sequelize": "^6.32.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /bezkoder-app/server.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const cors = require("cors"); 3 | 4 | const app = express(); 5 | 6 | var corsOptions = { 7 | origin: "http://localhost:8081" 8 | }; 9 | 10 | app.use(cors(corsOptions)); 11 | 12 | // parse requests of content-type - application/json 13 | app.use(express.json()); 14 | 15 | // parse requests of content-type - application/x-www-form-urlencoded 16 | app.use(express.urlencoded({ extended: true })); 17 | 18 | const db = require("./app/models"); 19 | db.sequelize.sync() 20 | .then(() => { 21 | console.log("Synced db."); 22 | }) 23 | .catch((err) => { 24 | console.log("Failed to sync db: " + err.message); 25 | }); 26 | 27 | // // drop the table if it already exists 28 | // db.sequelize.sync({ force: true }).then(() => { 29 | // console.log("Drop and re-sync db."); 30 | // }); 31 | 32 | // simple route 33 | app.get("/", (req, res) => { 34 | res.json({ message: "Welcome to bezkoder application." }); 35 | }); 36 | 37 | require("./app/routes/turorial.routes")(app); 38 | 39 | // set port, listen for requests 40 | const PORT = process.env.PORT || 8080; 41 | app.listen(PORT, () => { 42 | console.log(`Server is running on port ${PORT}.`); 43 | }); 44 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | postgresdb: 5 | image: postgres 6 | restart: unless-stopped 7 | env_file: ./.env 8 | environment: 9 | - POSTGRES_USER=$POSTGRESDB_USER 10 | - POSTGRES_PASSWORD=$POSTGRESDB_ROOT_PASSWORD 11 | - POSTGRES_DB=$POSTGRESDB_DATABASE 12 | ports: 13 | - $POSTGRESDB_LOCAL_PORT:$POSTGRESDB_DOCKER_PORT 14 | volumes: 15 | - db:/var/lib/postgres 16 | app: 17 | depends_on: 18 | - postgresdb 19 | build: ./bezkoder-app 20 | restart: unless-stopped 21 | env_file: ./.env 22 | ports: 23 | - $NODE_LOCAL_PORT:$NODE_DOCKER_PORT 24 | environment: 25 | - DB_HOST=postgresdb 26 | - DB_USER=$POSTGRESDB_USER 27 | - DB_PASSWORD=$POSTGRESDB_ROOT_PASSWORD 28 | - DB_NAME=$POSTGRESDB_DATABASE 29 | - DB_PORT=$POSTGRESDB_DOCKER_PORT 30 | stdin_open: true 31 | tty: true 32 | 33 | volumes: 34 | db: --------------------------------------------------------------------------------