shlogg · Early preview
Fahim Hasnain Fahad @fahimhasna13

Connecting NodeJS, NextJS & MongoDB With Docker Compose

Set up NodeJS backend & NextJS frontend with MongoDB local db using Docker. Created separate containers for each service, connected via docker-network & defined dependencies in docker-compose.yml file.

Recently, I had to create a NodeJS project for backend and a NextJS project for Frontend and connect MongoDB local database in NodeJS. 
I tried to run everything locally but using Docker gave me the most optimal way of running everything together inside different containers.

I have run all the projects and DB inside different containers. The Frontend will run at 3000 port, Backend will run at 8000 port and DB will run at 27017 port of localhost.
The Project structure was something like this:

project/
│
├── docker-compose.yml     # Where all the containers are declared
│
├── backend/...