# serviceberry-static

> Serviceberry plugin for serving static files

Latest version **1.0.3** (published 2025-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install serviceberry-static
pnpm add serviceberry-static
yarn add serviceberry-static
bun add serviceberry-static
```

## Health

**Score 35/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2025-03-07 |
| First published | 2020-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Bob Gray |
| Maintainers | bob-gray |
| Keywords | static, file, server |

## Links

- npm: https://www.npmjs.com/package/serviceberry-static
- Repository: https://github.com/bob-gray/serviceberry-static
- Homepage: https://github.com/bob-gray/serviceberry-static#readme
- Issues: https://github.com/bob-gray/serviceberry-static/issues
- npm.io page: https://npm.io/package/serviceberry-static

## Dependencies (2)

- [mime-types](https://npm.io/package/mime-types.md) ^2.1.27
- [serviceberry-cache-control](https://npm.io/package/serviceberry-cache-control.md) ^0.2.3

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2025-03-07
- 1.0.1 — 2020-09-17
- 1.0.0 — 2020-07-08

## README

serviceberry-static
===================

[![CircleCI](https://circleci.com/gh/bob-gray/serviceberry-static.svg?style=svg)](https://circleci.com/gh/bob-gray/serviceberry-static)
[![Test Coverage](https://api.codeclimate.com/v1/badges/2ca73a413e8e999a6b08/test_coverage)](https://codeclimate.com/github/bob-gray/serviceberry-static/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/2ca73a413e8e999a6b08/maintainability)](https://codeclimate.com/github/bob-gray/serviceberry-static/maintainability)
[![npm version](https://badge.fury.io/js/serviceberry-static.svg)](https://badge.fury.io/js/serviceberry-static)

[Serviceberry](https://serviceberry.js.org) plugin for serving static files.

Install
-------

```shell-script
npm install serviceberry-static
```

Usage
-----

This plugin streams static files from the file system. It also handles caching per the
[`cacheOptions`](https://www.npmjs.com/package/serviceberry-cache-control#options) argument and sets `ETag` and
`Last-Modified` headers using file stats. The base path to the static files in the file system can be set explicitly
with the `basePath` argument, or it can implicit - based on the current path of the request.

```js
const staticFiles = require("serviceberry-static");

trunk.at("url/path/to/static").use(staticFiles());
```

staticFiles([basePath[, cacheOptions[, contentTypes]]])
-----------------------------------

  - **basePath** *string or null*

    If *basePath* is a string, it will be the base path of the static files served. For example, if the plugin is
    registered at `"url/path/to/static"` and the *basePath* argument passed to the plugin is `"/some/folder"` and request
    path is *url/path/to/static/awesome/pic.jpg*, then the file will be served from */some/folder/awesome/pic.jpg*.

    If *basePath* is `undefined` or `null` the request path will be used to serve the file from the current working
    directory. Given the example above, the file will be served from *{cwd}/url/path/to/static/awesome/pic.jpg*

  - **cacheOptions** *object*

    See [serviceberry-cache-control](https://www.npmjs.com/package/serviceberry-cache-control#options).

  - **contentTypes** *object*
  
    *Common file content types should work without listing them here.* Property names are file extension names and
    property values are file content types. This argument is useful when files have no extension (`""`) or for unusual
    file extensions.

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