- React.js
- Material-UI
- MongoDB
- Mongoose
- Moleculer
- Node.js
- Docker
Working with Moleculer makes it super easy to deploy a scalable microservices architecture. This application is built as shown in the following diagram:
All nodes are loosely coupled which means that we can deploy this application in such a way that is resilient, scalable and fault tolerant. We can spin-up as many nodes as we need per service.
- cd frontend
- npm install
- create file
.env.development.local
in the frontend directory and add the following content to this file:REACT_APP_API_URL=http://localhost:4000/api
- npm start
- cd backend
- npm install
- create directory
config
- create file
dev.env
insideconfig
directory - Add this content to
dev.env
:
MONGODB_URL=<your mongo url pointing to application db> # for example: MONGODB_URL=mongodb://127.0.0.1:27017/moleculer-todoapp PORT=4000
- go back to
backend
folder - npm run dev
To run unit tests
- create file
test.env
insideconfig
directory - Add following content
MONGODB_URL=<your mongo url pointing to test db> # for example: MONGODB_URL=mongodb://127.0.0.1:27017/moleculer-todoapp-test
- Now, go back to
backend
folder and runnpm run test
The above instructions basically run the backend in a monolitic way. To run independent nodes per service, Moleculer includes a handy script that creates a docker container per service. To deploy the containers, cd
into the backend
folder and simply run:
npm run dc:up
This will create the needful images and build the containers. For instance, here is the output of docker ps
from the live demo server of this app: