# @leonardosarmentocastro/server

> minimal production server

Latest version **2.0.0** (published 2023-12-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install @leonardosarmentocastro/server
pnpm add @leonardosarmentocastro/server
yarn add @leonardosarmentocastro/server
bun add @leonardosarmentocastro/server
```

## 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 | 2023-12-07 |
| First published | 2021-05-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | leonardo.sarmentocastro |
| Maintainers | leonardosarmentocastro |
| Keywords | minimal, production, server |

## Links

- npm: https://www.npmjs.com/package/@leonardosarmentocastro/server
- npm.io page: https://npm.io/package/@leonardosarmentocastro/server

## Dependencies (3)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [express](https://npm.io/package/express.md) ^4.17.1
- [mongoose](https://npm.io/package/mongoose.md) 6.5.0

## Recent versions

- 2.0.0 (latest) — 2023-12-07
- 1.0.0 — 2022-08-04
- 0.0.2 — 2021-05-09
- 0.0.1 — 2021-05-04

## README

# server - minimal production server

Create a production ready Express.js server with start/listen/close capabilities.

## How it works

The simplest way to get a server with health-check up and running would be:

```js
const server = require('@leonardosarmentocastro/server');

(async () => {
  const port = 8080;
  const api = await server.start(port);
  
  const body = await fetch(`http://127.0.0.1:${port}/`).json();
  console.log(body); // `{ application: 'up' }`
  
  await server.close(api);
})();
```

You can customize your own routes by:

```js
const port = 8080;
const api = await server.start(port, {
  routes: (app) => {
    app.get('/custom-route', (req, res) => res.json({ customizable: true }))
  },
});

const body = await fetch(`http://127.0.0.1:${port}/custom-route`).json();
console.log(body); `{ customizable: true }`
```

Or even attach application middlewares:

```js
const port = 8080;
const api = await server.start(port, {
  middlewares: (app) => {
    app.use((req, res, next) => {
      res.set('customizable', true);
      next();
    });
  },
});

const response = await fetch(`http://127.0.0.1:${port}`);
console.log(response.headers.customizable); // `"true"`
```

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