# connect-static-file

> connect and express middleware to serve a single static file

Latest version **2.0.0** (published 2017-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install connect-static-file
pnpm add connect-static-file
yarn add connect-static-file
bun add connect-static-file
```

## 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 | 2017-10-04 |
| First published | 2015-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Joris van der Wel |
| Maintainers | joris-van-der-wel |
| Keywords | static, gzip, gz, express, connect, file, compress, middleware |

## Links

- npm: https://www.npmjs.com/package/connect-static-file
- Repository: https://github.com/Joris-van-der-Wel/connect-static-file
- Issues: https://github.com/Joris-van-der-Wel/connect-static-file/issues
- npm.io page: https://npm.io/package/connect-static-file

## Dependencies (3)

- [mime](https://npm.io/package/mime.md) ^1.3.4
- [send](https://npm.io/package/send.md) ^0.16.0
- [accepts](https://npm.io/package/accepts.md) ^1.2.5

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2017-10-04
- 1.2.1 — 2017-10-04
- 1.2.0 — 2017-05-17
- 1.1.2 — 2015-11-22
- 1.1.1 — 2015-11-22
- 1.1.0 — 2015-11-20
- 1.0.3 — 2015-04-25
- 1.0.2 — 2015-04-10
- 1.0.1 — 2015-03-21
- 1.0.0 — 2015-03-21

## README

connect-static-file
===================
[![Build Status](https://travis-ci.org/Joris-van-der-Wel/connect-static-file.svg?branch=master)](https://travis-ci.org/Joris-van-der-Wel/connect-static-file) 

Connect/express middleware to serve a single static file

Usage
-----
```javascript
var express = require('express');
var staticFile = require('connect-static-file');

var app = express();
var path = 'path/to/file.txt';
var options = {};
app.use('/foo.txt', staticFile(path, options));
```

### Options

#### etag

Enable or disable etag generation, defaults to true.

#### extensions

If a given file doesn't exist, try appending one of the given extensions,
in the given order. By default, this is disabled (set to `false`). An
example value that will serve extension-less HTML files: `['html', 'htm']`.
This is skipped if the requested file already has an extension.

#### lastModified

Enable or disable `Last-Modified` header, defaults to true. Uses the file
system's last modified value.

#### maxAge

Provide a max-age in milliseconds for http caching, defaults to 0.
This can also be a string accepted by the
[ms](https://www.npmjs.org/package/ms#readme) module.

#### headers

Any additional headers you would like to set on the response. This is a plain old javascript object: `headers: {'X-Foo': 'bar'}`

#### encoded

If set, assume the static file has been encoded using the specified encoding. For example `encoded: 'gzip'`. This value must be a valid `Content-Encoding` [token](https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding).
If the browser does not support this encoding _(the encoding is not specified in the `Accept-Encoding` request header)_, this middleware will pass on the request to the next middleware. The `Content-Encoding` header will be set so that the browser will uncompress the file on the fly.

This is useful if you are compressing your static files beforehand:

```javascript
app.use('/bundle.js', staticFile('generated/bundle.js.gz', {encoded: 'gzip'}));
// If the file is missing, or if the browser does not support gzip, use this one instead:
app.use('/bundle.js', staticFile('generated/bundle.js'));
```

Other modules
-------------
If you would like to server an entire directory of possible gziped files, take a look at [connect-gzip-static](https://www.npmjs.com/package/connect-gzip-static) or [ecstatic](https://www.npmjs.com/package/ecstatic). If you would like dynamic gzip compression, try [compression](https://www.npmjs.com/package/compression)

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