# server-hook

> Simple server status hook for status-board.

Latest version **1.0.4** (published 2021-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install server-hook
pnpm add server-hook
yarn add server-hook
bun add server-hook
```

## 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.4 |
| Published | 2021-12-22 |
| First published | 2021-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | psylucidos |
| Maintainers | psylucidos |

## Links

- npm: https://www.npmjs.com/package/server-hook
- Repository: https://github.com/psylucidos/status-board
- Homepage: https://github.com/psylucidos/status-board#readme
- Issues: https://github.com/psylucidos/status-board/issues
- npm.io page: https://npm.io/package/server-hook

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.22.0

## Recent versions

- 1.0.4 (latest) — 2021-12-22
- 1.0.3 — 2021-12-01
- 1.0.2 — 2021-11-28
- 1.0.1 — 2021-11-21
- 1.0.0 — 2021-11-19

## README

## Server-hook
A simple script that posts project data to an API.
### Example Usage
```javascript
// setup server and import hook
const Koa = require('koa');
const hook = require('server-hook');

const app = new Koa();
const api = require('./api');
hook.init({ // initialise hook
  target: 'http://example.com:3000/api',
  projectName: 'test',
  interval: 60,
})

app.on('error', err => {
  hook.logErr(err);
});

app
  .use(async (ctx, next) => {
    // create simple response time recorder
    const start = Date.now();
    await next();
    const ms = Date.now() - start;
    hook.request(ms); // update hook
  })
  .use(api.middleware());

app.listen(8080);
hook.setStatus('Online');
hook.log('Listening on 8080');
```
### Functions
#### .init(config)
*config*: `{
  target: 'http://exampleapi.com/api',
  projectName: 'testProject',
  interval: '60' // in seconds
}`

Function establishes a connection with the webapp api and updates api at a set interval.
#### .request(responseTime)
*responseTime*: `Number // in seconds`

Records incidence of server request along with reponse time.
#### .setStatus(status)
*status*: `String // either 'Online'/'Offline' or other`

Records project production status.
#### .login()
Records user or API key login.
#### .setAccounts(accounts)
*accounts*: `Number`

Records number of user accounts.
#### .log(msg)
*msg*: `String`

Records logged message and displays through console.log.
#### .logErr(err)
*err*: `Error`

Records logged error message and displays through console.error.

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