# uw-microbe.js

> A tiny service bootstrap.

Latest version **2.0.0** (published 2017-01-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install uw-microbe.js
pnpm add uw-microbe.js
yarn add uw-microbe.js
bun add uw-microbe.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2017-01-16 |
| First published | 2017-01-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | michael-donat |

## Links

- npm: https://www.npmjs.com/package/uw-microbe.js
- Repository: https://github.com/utilitywarehouse/uw-microbe.js
- Homepage: https://github.com/utilitywarehouse/uw-microbe.js#readme
- Issues: https://github.com/utilitywarehouse/uw-microbe.js/issues
- npm.io page: https://npm.io/package/uw-microbe.js

## Dependencies (7)

- [uuid](https://npm.io/package/uuid.md) ^3.0.1
- [express](https://npm.io/package/express.md) ^4.14.0
- [canister.js](https://npm.io/package/canister.js.md) ^1.6.1
- [director.js](https://npm.io/package/director.js.md) ^1.2.0
- [@utilitywarehouse/uw-lib-logger.js](https://npm.io/package/@utilitywarehouse/uw-lib-logger.js.md) ^1.0.0
- [@utilitywarehouse/uw-lib-prometheus.js](https://npm.io/package/@utilitywarehouse/uw-lib-prometheus.js.md) ^1.0.9
- [@utilitywarehouse/uw-lib-operational.js](https://npm.io/package/@utilitywarehouse/uw-lib-operational.js.md) ^1.0.0

## Recent versions

- 2.0.0 (latest) — 2017-01-16

## README

# uw-microbe.js

Microbe is an abstraction for the repetitive task of setting basic express infrastructure each time we bring up another μService.


## API

- `new Microbe([root = process.cwd()])` - create an instance of a service passing it's name (used for loggers etc.) and root directory (for operational endpoitns etc.)
- `Microbe.build()` - builds the system, needs to be called before starting
- `Microbe.start(port)` - starts the server on given port
- `Microbe.container` - returns instance of DI container
- `Microbe.configure(configPath)` - loads yml file into canister.js configuration
- `Microbe.before(middleware)` - attaches middleware to run before any routes are evaluated
- `Microbe.after(middleware)` - attaches middleware to run after routes are evaluated
- `Microbe.route() : express.Router` - returns an instance of Router, attach your handlers here
- `Microbe.health(callback)` - adds a health checker per uw-lib-operational.js
- `Microbe.ready(callback)` - sets a ready checker per uw-lib-operational.js


## Bits out of the box

### Logging

There's both request and error logging via bunyan available out of the box.

A request scope logger, with `request-id` and `x-request-id` is available on `req.logger` property.

### Instrumentation

Available in the container via `get('instrumentation')`. Default heap and request durations are preconfigured as well as `/__/metrics` for reporter.

### Health

Endpoints exposed via default `/__/{name}` routes. You can configure your checks as described in the API section above.

### Other services

Check [wiring.yml](wiring.yml) for additional services.

### Wiring

For reference on wiring go to https://github.com/michael-donat/canister.js

### Before/After ware

Those can be added by either using your the API or tagging services with `before.router` and `after.router`.  

## Example

```nodejs
const Microbe = require('uw-microbe.js');

const system = new Microbe(__dirname);

system.configure('./wiring.yml');
system.build();

system.router.get('/', (req, res) => {
	res.json({ok: true});
})

system.pre.use((req, res, next) => {
	console.log('Some preware');
	next();
});

system.start(3321);
```

---
_Source: https://npm.io/package/uw-microbe.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
