# @cisl/express

> An opinionated express depending on cog.json

Latest version **1.0.4** (published 2022-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cisl/express
pnpm add @cisl/express
yarn add @cisl/express
bun add @cisl/express
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-03-08 |
| First published | 2020-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matthew Peveler |
| Maintainers | masterodin, masterodinbot |

## Links

- npm: https://www.npmjs.com/package/@cisl/express
- Repository: https://github.com/cislrpi/express
- Homepage: https://github.com/cislrpi/express#readme
- Issues: https://github.com/cislrpi/express/issues
- npm.io page: https://npm.io/package/@cisl/express

## Dependencies (13)

- [ws](https://npm.io/package/ws.md) ^7.5.7
- [ejs](https://npm.io/package/ejs.md) ^3.1.6
- [express](https://npm.io/package/express.md) ^4.17.1
- [@types/ws](https://npm.io/package/@types/ws.md) ^7.4.7
- [@types/ejs](https://npm.io/package/@types/ejs.md) ^3.1.0
- [@types/node](https://npm.io/package/@types/node.md) ^12.0.10
- [serve-static](https://npm.io/package/serve-static.md) ^1.14.1
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.4
- [serve-favicon](https://npm.io/package/serve-favicon.md) ^2.5.0
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.0
- [@types/serve-static](https://npm.io/package/@types/serve-static.md) ^1.13.2
- [@types/cookie-parser](https://npm.io/package/@types/cookie-parser.md) ^1.4.1
- [@types/serve-favicon](https://npm.io/package/@types/serve-favicon.md) ^2.2.31

## Recent versions

- 1.0.4 (latest) — 2022-03-08
- 1.0.3 — 2020-04-24

## README

# @cisl/express

An opinionated wrapper around the popular [express](https://expressjs.com/) and
[websockets/ws](https://github.com/websockets/ws) libraries. It assumes that you are running
an application with a `cog.json` file.

The library assumes that you want to use `cookie-parser`, JSON (with `2` spaces),
and the `ejs` as the view engine. Finally, the port is read in from the `cog.json` file.

## Installation

```bash
npm install @cisl/express
```

## Usage

In straight JS:

```js
const express = require('@cisl/express');
const app = express();
app.listen();
```

or in TypeScript:

```typescript
// or typescript
import express from '@cisl/express';
const app = express();

app.listen();
```

The `listen` method above does not accept any parameters, and will automatically use the
port specified in the `cog.json` file that should exist in current working directory when
running the above.

After creating the object, it can be used as a regular express app:

```js
app.get('/', (req, res) => {
    res.json({'msg': 'Hello World'});
});
```

as well as accessing the attached WebSocket server:

```js
app.wsServer.on('connection', (socket) => {
    console.log('a user connected');
    socket.on('message', data => {
        console.log(`Received: ${data}`);
        socket.send('pong');
    });
});
```

The available objects off the original (in addition to the normal express stuff) is:

* `expressListen` - original express listen method, should largely not be necessary/used over `listen()`
* `httpServer` - the underlying `HttpServer` instance
* `wsServer` - the underlying `WebSocket.Server` instance

Finally, the package will automatically add a `/test` GET route that returns
a JSON object with the following definition:

```json
{
    "response": "AOK",
    "error": null
}
```

which can be used as a small healthcheck for apps running `@cisl/express`.

## Configuration

Using this package assumes you have a `cog.json` file with at least the following
in it:

```typescript
{
    "port": number
}
```

## Output

`@cisl/express` will only output a single line when you run the `listen()` command with
the following message `@cisl/express listening on port <PORT>`. This will be output as
a standard `console.log`, or if you have `@cisl/logger` installed, using `logger.info`.
You can silence the output, by sending `{quiet: True}` to the `express()` method above.

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