# @liamnewmarch/static-server

> A minimal HTTP server for static files.

Latest version **0.1.1** (published 2020-05-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @liamnewmarch/static-server
pnpm add @liamnewmarch/static-server
yarn add @liamnewmarch/static-server
bun add @liamnewmarch/static-server
```

Provides the command `static-server`.

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-05-06 |
| First published | 2020-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 2 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Liam Newmarch |
| Maintainers | liamnewmarch |

## Links

- npm: https://www.npmjs.com/package/@liamnewmarch/static-server
- Repository: https://github.com/liamnewmarch/static-server
- Homepage: https://github.com/liamnewmarch/static-server#readme
- Issues: https://github.com/liamnewmarch/static-server/issues
- npm.io page: https://npm.io/package/@liamnewmarch/static-server

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.27

## Recent versions

- 0.1.1 (latest) — 2020-05-06
- 0.1.0 — 2020-05-06

## README

# Static server

A minimal HTTP server for static files.

Really, really minimal. In fact there are only two dependencies, [chalk](https://www.npmjs.com/package/chalk) and [mime-types](https://www.npmjs.com/package/mime-types), the rest is handled by a custom file system handler for Node [http](https://nodejs.org/api/http.html).

The server can be used via the CLI or imported as a module.

## Install

```
npm install @liamnewmarch/static-server
```

## CLI usage

```
Usage: static-server [options]

A minimal HTTP server for static files

Options:
  -V, --version           output the version number
  -h, --help              display help for command
  -6, --ipv6              force use of IPv6  (default: false)
  -d, --directory <path>  directory to serve (default: ".")
  -H, --host <name>       host name to use   (default: use OS default)
  -p, --port <port>       port number to use (default: use OS default)
```

## Module

Simple version, serves the current directory (not recommended) on a random port

```js
import { staticServer } from '@liamnewmarch/static-server';

staticServer();
```

More complex version, serves a `static` folder at http://localhost:3000 with a custom handler for http://localhost:3000/hello-world.

```js
import { staticServer } from '@liamnewmarch/static-server';

// All options are optional
const options = {
  directory: 'static',
  host: '127.0.0.1',
  port: 3000,
  ipv6: false,
  handlers: [
    myCustomHandler,
  ],
};

function myCustomHandler(request, response, next) {
  // Custom handlers use request and response from the Node http API
  if (request.url === '/hello-world') {
    response.writeHead(200, { 'Content-Type': 'text/plain' });
    response.end('Hello, world!', 'utf-8');
  }
  // The next() callback tells the request listener to use the next handler
  next();
}

staticServer(options);
```

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