# slim-node-server

> Simple and slim Node.js HTTP server

Latest version **1.1.6** (published 2020-02-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install slim-node-server
pnpm add slim-node-server
yarn add slim-node-server
bun add slim-node-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 | 1.1.6 |
| Published | 2020-02-10 |
| First published | 2019-12-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 47.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jake Cyr |
| Maintainers | jakecyr |
| Keywords | http-server, slim framework, framework |

## Links

- npm: https://www.npmjs.com/package/slim-node-server
- Repository: https://github.com/jakecyr/slim-node-server
- Homepage: https://github.com/jakecyr/slim-node-server#readme
- Issues: https://github.com/jakecyr/slim-node-server/issues
- npm.io page: https://npm.io/package/slim-node-server

## Dependencies (1)

- [cookie](https://npm.io/package/cookie.md) ^0.4.0

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 1.1.6 (latest) — 2020-02-10
- 1.1.5 — 2020-02-10
- 1.1.4 — 2020-02-06
- 1.1.3 — 2019-12-30
- 1.1.2 — 2019-12-30
- 1.1.1 — 2019-12-30
- 1.1.0 — 2019-12-30
- 1.0.12 — 2019-12-30
- 1.0.11 — 2019-12-30
- 1.0.10 — 2019-12-30
- 1.0.9 — 2019-12-20
- 1.0.8 — 2019-12-19
- 1.0.7 — 2019-12-19
- 1.0.6 — 2019-12-18

## README

# Slim Node.js HTTP Server

[![Build Status](https://travis-ci.com/jakecyr/slim-node-server.svg?branch=master)](https://travis-ci.com/jakecyr/slim-node-server)

## Installation

* Install the npm package `npm install slim-node-server`
* Import the module to your project (see example below)

## Usage

After installing installing the framework, create a new instance of `Slim` and start creating your server:

```javascript
// import slim framework
const Slim = require('slim-node-server');

// create new slim server with logging
let app = new Slim(true);

app
    .get('/', (req, res) => {
        res.end('nothing here yet');
    })
    .get('/some-json', (req, res) => {
        res.json({ task: 'Task 1' });
    })
    .listen(8080, '0.0.0.0', () => {
        console.log('Listening');
    });
```

### Middleware

* All request types support middleware functions
* The last function must end the response
* All route handler functions are executed in the order they are specified

Example:
```javascript
function log(req, res, next) {
    console.log('LOG VISIT', req.url);
    next();
}

// add middleware to log page url visited to server console
app.get('/', log, (req, res) => {
    res.end('Visit has been logged');
});
```

### Query Parameters

Parse query parameters as needed using the `request` object in a handler function. Example:

```javascript
app.get('/echo-name', (req, res) => {
    const queryParams = req.query();
    res.end(queryParams.name);
})
```

### Body Parsing

Parse a payload body as needed using the `request` object in a handler function. Example:

```javascript
app.post('/', async (req, res) => {
    // wait for all payload data to parse
    const payload = await req.body();

    // echo back the payload to the client
    res.json(payload);
})
```

### Router

Routes can be imported from other files to reduce file size. Example:

```javascript
app
    .addRoutes('/api', require('./routes/'))
    .listen(8080, '0.0.0.0', () => console.log('Server listening'));
```

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