Express with superpowers! Effortless clustering, CLI logging & colors with Express.
Support us on Patreon to get priority updates on our development plan and voting power on new features.
Installation
Install Express Power with yarn or npm:
yarn add express-power
npm install express-power
Usage & Examples
Minimal example
const Power = ; const worker = { app;}; Power;
Extended Example
const Power = ;const log = Power; const master = { ;}; const worker = { app; app;}; let options = workers: 8 logToFile: true path: __dirname + "/power.log" master worker; Power;
In production, usage of pm2 to run your Express Power app is strongly recommended.
Options
Power options you can use in Power.load(options);
Option | Default Value | What it does |
---|---|---|
workers | 2 | Number of workers. |
logToFile | false | Enable logging to file. |
path | appDirectory + '/power.log' | Log filename. |
master | () => {} | Function to execute before spawning master process. You can welcome the user and run pre-checks here. |
worker | () => {} | Function to execute after spawning worker process. Your Express app should be handled here. |
autoRestart | true | Restarts automatically a worker when it dies. Useful for keeping your process alive when unexpected errors occur. |
Full Reference
Require Express Power this way:
const Power = require('express-power');
Now, the exported elements are:
const {load, log, italy} = Power;
Let's see them in detail:
Element | What it does | Proto |
---|---|---|
load | Powers Express | load(options) |
log | Power logs to console | log(text) |
italy | Colors text as Italian flag | italy(text) / text.italy |
Power options you can use in load(main, options);
Option | Default Value | What it does |
---|---|---|
workers | 2 | Number of workers. |
logToFile | false | Enable logging to file. |
path | appDirectory + '/power.log' | Log filename. |
master | () => {} | Function to execute before spawning master process. You can welcome the user and run pre-checks here. |
worker | () => {} | Function to execute after spawning worker process. Your Express app should be handled here. |
autoRestart | true | Restarts automatically a worker when it dies. Useful for keeping your process alive when unexpected errors occur. |
Notice: this package uses Colors internally, which extends the String prototype.
Contributing
Feel free to open an Issue or send me a direct message.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Honeyside - Honeyside
License
This project is licensed under the MIT License - see the LICENSE.md file for details.