Added in: v0.8.0
There is a project runner helper script in the Moleculer project. You can use it if you want to create small repos for services. In this case you needn’t to create a ServiceBroker with options. Just create a
moleculer.config.json file in the root of repo fill it with your options and call the
moleculer-runner within the NPM scripts.
As an other solution you can put it to the environment variables instead of putting options to file.
In production we recommend to put options to the environment variables! Use the
moleculer.config.jsonly in development.
Please note! It’s working in this format in NPM scripts. If you want to call it directly from your console, use the
||If true, it will switch to REPL mode after broker started.|
||Disable the logger of broker. It won’t print anything to the console.|
||Use it if you store your configuration file in different path or with different filename.|
Example NPM scripts
As you can see above we defined two scripts. The
dev script load the development configurations from the
moleculer.dev.config.js file, start all your services from the
services folder and switch to REPL mode. You can call it with
npm run dev command.
start script is try to load the default
moleculer.config.js file if it exists, or load options from environment variables. After that, start all your services from the
services folder. You can call it with
npm start command.
The runner does the following steps to load & merge configurations:
- If you defined config file in CLI options, try to load it. If it’s not exist, throw an error.
- If you not defined, try to load the
moleculer.config.jsfile from the current directory. If it’s not exist try to load the
- If it found any config file, load it and merge options with the default options of the ServiceBroker.
- The runner walks through the options and try to override them from environment variables. So if you set
logLevel: "warn"in the config file, but define the
LOGLEVEL=debugenvironment variable, the runner will override it and the result will be
The structure of the configuration file is same as the broker options. Every property has the same name. Use shorthand formats in
Example config file
The runner transforms the property names to uppercase. If it is a nested property, it joins names with
Example environment variables
If you define service files or folders in CLI arguments, the runner will try to load them. If you define folder(s), the runner will load all services
*.service.js from this folder(s). You can define services & service folder with
SERVICEDIR environment variables.
- If it find
SERVICEDIRenv, but isn’t find
SERVICESenv, it’ll load all services from the
- If it find
SERVICESenv, it’ll load the specified services from the
- If it’s not find
SERVICEDIRenv but find
SERVICESenv, load the specified services from the current directory.
It will load the
user.service.js files from the
It will load all
*.service.js files from the