# microservice-wrapper

> A node.js microservice server wrapper

Latest version **1.0.0** (published 2017-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install microservice-wrapper
pnpm add microservice-wrapper
yarn add microservice-wrapper
bun add microservice-wrapper
```

## 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 | 1.0.0 |
| Published | 2017-03-19 |
| First published | 2017-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Armando Magalhães |
| Maintainers | armand1m |

## Links

- npm: https://www.npmjs.com/package/microservice-wrapper
- Repository: https://github.com/armand1m/node-microservice-wrapper
- Homepage: https://github.com/armand1m/node-microservice-wrapper#readme
- Issues: https://github.com/armand1m/node-microservice-wrapper/issues
- npm.io page: https://npm.io/package/microservice-wrapper

## Dependencies (3)

- [consul](https://npm.io/package/consul.md) ^0.28.0
- [microservice-info](https://npm.io/package/microservice-info.md) ^1.0.2
- [microservice-events](https://npm.io/package/microservice-events.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2017-03-19

## README

# node-microservice-wrapper [![Build Status](https://travis-ci.org/armand1m/node-microservice-wrapper.svg?branch=master)](https://travis-ci.org/armand1m/node-microservice-wrapper)

> A node.js microservice server wrapper

This module is a wrapper for a microservice implementation.

You can do your webserver implementation using whatever framework you do want, use this module to wrap your server, and then start it using the wrapper instance.

When started, it will automatically subscribe your webserver to a consul instance. It will use the `microservice-info` module to fetch information about your webserver to send to the consul server.

## Install

```
$ npm install --save microservice-wrapper
```

## Usage

Lets say you have a `service.js` and an `index.js` file, and you want to build your microservice using Express.

 - `service.js`:
```js
const Info = require('microservice-info')
const express = require('express')
const app = express()

app.get(`/${Info.name}/health`, (req, res) => {
  res.send('{ "status": "health" }')
})

module.exports = {
  start(port) {
    return new Promise((resolve, reject) => {
      let instance = app.listen(port, err => {
        if (err) {
          return reject(err)
        }

        return resolve(instance)
      })
    })
  },
  stop(instance) {
    return new Promise((resolve, reject) => {
      instance.close(() => {
        resolve()
      })
    })
  }
}

```

 - `index.js`
```js
const MicroserviceWrapper = require('microservice-wrapper')
const service = require('./service')

new MicroserviceWrapper(service).start()
```

## License

MIT © [Armando Magalhães](http://armand1m.herokuapp.com)

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