This is dummy but extended example of a NodeJS microservice that can be used as a base for creating new one, more reliable and complete. It was created as resulting from my study about microservices which I did from my short experience creating NodeJS APIs and reading some good tutorials listed bellow.
I hope it can help you learn about microservice and enhance this base.
Considere the microServiceBaseProducer running in other terminal for a complete example.
This microservices acts like a messaging consumer
- config: contains the configuration files with the parameters used by the microservice (rename de default.json.template to default.json and fullfill it with your own parmeters)
- db: contains the MongoDB connection object
- models: contains all the models responsible for manipulating the data (documents) from/to MongoDB
- services: contains serives that interacts with the external world and other tools (RabbitMQ, fi)
- utils: contains other general purpose utilities like logger object
- have a MongoDB instance running
- have a RabbitMQ instance running
- rename config/defaul.json.template to config/default.json
- fullfill the config/defaul.json with you own parameters
- install the packages
npm i
- run
npm start
- have a microServiceBaseProducer running and access its endpoints :-)
I'm thankfull for the these guys who helped me to learn about NodeJS microservices, MongoDB and RabbitMQ: