This is a Moleculer-based microservices base project. Written in Typescript
Based on moleculer typescript template (https://github.com/moleculerjs/moleculer-template-project-typescript/tree/master/template) With following addtional features:
- ESM base project
- Decorators support for Actions, Methods, Event... (with sample)
- Decorators support for Bull Queue (with sample)
- Swagger auto-generated from decorators
- Access RDBMS using projectionjs (with sample)
- With support for Soft delete
- Code quality tools
- EditorConfig support (https://editorconfig.org/)
- Pre-configured Pretier
- Pre-configured esLint (inherited from airbnb config) with some modifications)
- broker.call() by static link instead of strings (easier for source code navigation: Ctrl-Click)
- Unit test with jest
- Enforment of git commit policies:
- Lint error free (auto run lint for all staged file before "git commit")
- force pretier before commit
- Force run gitleaks to check if in the commit has credential leaks...
- follow "Semantic Commit Message" policies using husky and lint-staged
- force run "yarn test" and "yarn lint" (full lint for whole repository) before push
- Support of a faster compiler (SWC/ESBUILD) rather TSC
- Auto configure (Enforcement of default value for required settings)
- Easy configuration for Jaeger/OpenTracing
- Easy version management for services
- Change it to a template, so can be used with
moleculer init
- Hot reload when code changes (--watch)
- Convert to yarn2
- Samples for authentication
- bullboard
- yarn test only few branches
And lots more...
- Cannot use module alias when importing. Need to use relative path import (it's actually problem of ESM loader with ts-node). Will try to fix later
- QueueHander: Cannot acess "this" inside queue handler. If you need to access "this", include it in the payload when creating jobs
Reference: https://ec.europa.eu/component-library/v1.15.0/eu/docs/conventions/git/
Start the project with npm run dev
command.
After starting, open the http://localhost:3000/ URL in your browser.
On the welcome page you can test the generated services via API Gateway and check the nodes & services.
In the terminal, try the following commands:
nodes
- List all connected nodes.actions
- List all registered service actions.call greeter.hello
- Call thegreeter.hello
action.call greeter.welcome --name John
- Call thegreeter.welcome
action with thename
parameter.call products.list
- List the products (call theproducts.list
action).
yarn dev
: Start development mode (load all services locally with hot-reload & REPL)yarn start
: Start production mode (setSERVICES
env variable to load certain services)yarn cli
: Start a CLI and connect to production. Don't forget to set production namespace with--ns
argument in scriptyarn lint
: Run ESLint
- api: API Gateway services
- greeter: Sample service with
hello
andwelcome
actions. - products: Sample DB service. To use with MongoDB, set
MONGO_URI
environment variables and install MongoDB adapter withnpm i moleculer-db-adapter-mongo
.
- db.mixin: Database access mixin for services. Based on moleculer-db
- Moleculer website: https://moleculer.services/
- Moleculer Documentation: https://moleculer.services/docs/-1.14/