# fs-serve

> Serve static files with HTTP

Latest version **4.3.0** (published 2024-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install fs-serve
pnpm add fs-serve
yarn add fs-serve
bun add fs-serve
```

Provides the command `fs-serve`.

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.3.0 |
| Published | 2024-11-09 |
| First published | 2021-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dwbinns |

## Links

- npm: https://www.npmjs.com/package/fs-serve
- Repository: https://github.com/dwbinns/fs-serve
- Issues: https://github.com/dwbinns/fs-serve/issues
- npm.io page: https://npm.io/package/fs-serve

## Recent versions

- 4.3.0 (latest) — 2024-11-09
- 4.2.0 — 2024-10-14
- 4.1.0 — 2024-09-30
- 4.0.0 — 2024-09-20
- 3.2.0 — 2023-07-03
- 3.1.0 — 2023-05-08
- 3.0.0 — 2023-02-14
- 2.0.4 — 2022-07-12
- 2.0.3 — 2022-07-12
- 2.0.2 — 2022-07-12
- 2.0.1 — 2022-06-03
- 2.0.0 — 2022-06-03
- 1.0.0 — 2021-09-26

## README

# Serve static files with HTTP

Serve static files with:

- configurable directory listing
- a wide range of pre-configured mime-types
- charset **utf-8** for text file types
- configurable caching (including **etags** and custom **max-age**)
- streamed responses

## Usage (CLI)

Serve the content of this directory. Directory listing are enabled:
```
npm install -g fs-serve
fs-serve
```

Serve the content of the wwww on port 3333 to localhost:
```
fs-serve path www port 3333
```

## Usage (JS)

```
npm install fs-serve
```

Note that only ES module imports are supported (not `require`)

```js
import Server from "fs-serve";

let httpServer = await new Server("www").listen(3000);
console.log(await (await fetch("http://localhost:3000/")).text());
httpServer.close();
```

## API

```js
import Server from "fs-serve";

let directory = "www";
// Create a new server
const server = new Server(directory, {
  directoryList: false,
  log: (url, statusCode, result) => console.log(url, statusCode, result),
  maxAge: 2,
  ssi: {
    extension: ".shtml",
    handlers: [Server.includeVirtual]
  }
});
```

- directoryList - set to **true** to enable directory lists - default **false**
- log - provide a callback for custom logging, or set to falsy to disable logging - default **console.log**
- maxAge - how many seconds a client should cache a response - default **2** seconds
- ssi - a list of extensions with SSI handlers

Serve a request in an existing web server:

```js
import Server from "fs-serve";
import http from "http";

const server = new Server("www");

http.createServer((req, res) => server.serve(request, response));
```

Create an http server and listen on port and host:

```js
import Server from "fs-serve";

let port = 4444;
let host = "localhost";
let httpServer = await new Server("www").listen(port, host);
httpServer.close();
```

The port will be selected automatically if omitted, and the server will listen on all addresses if the host is omitted.
See https://nodejs.org/api/net.html#serverlisten for details.

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