# static-server

> A simple http server to serve static resource files from a local directory.

Latest version **2.2.1** (published 2018-04-03) · MIT license · 0 weekly downloads

## Install

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

Provides the command `static-server`.

## Health

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2018-04-03 |
| First published | 2013-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 5 |
| Unpacked size | 28.7 KB |
| Known vulnerabilities | 1 |
| Install scripts | no |
| GitHub stars | 208 |
| Author | Eduardo Bohrer |
| Maintainers | nbluis |
| Keywords | static, server, local, assets |

## Links

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

## Dependencies (5)

- [opn](https://npm.io/package/opn.md) ^5.2.0
- [mime](https://npm.io/package/mime.md) ^1.2.11
- [chalk](https://npm.io/package/chalk.md) ^0.5.1
- [commander](https://npm.io/package/commander.md) ^2.3.0
- [file-size](https://npm.io/package/file-size.md) 0.0.5

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2018-04-03
- 2.2.0 — 2018-03-05
- 3.0.0 — 2017-11-26
- 2.1.0 — 2017-11-26
- 2.0.6 — 2017-10-24
- 2.0.5 — 2017-07-18
- 2.0.4 — 2017-01-22
- 2.0.3 — 2016-07-06
- 2.0.2 — 2016-03-15
- 2.0.1 — 2015-12-28
- 2.0.0 — 2014-12-08
- 1.0.2 — 2014-11-10
- 1.0.1 — 2014-08-19
- 1.0.0 — 2013-09-19

## README

[![Build Status](https://secure.travis-ci.org/nbluis/static-server.svg?branch=master)](http://travis-ci.org/nbluis/static-server)

# Node static server
A simple http server to serve static resource files from a local directory.

## Getting started
* [Install node.js](http://nodejs.org/download/)
* Install npm package globally `npm -g install static-server`
* Go to the folder you want to serve
* Run the server `static-server`

## Options

    -h, --help                 output usage information
    -V, --version              output the version number
    -p, --port <n>             the port to listen to for incoming HTTP connections
    -i, --index <filename>     the default index file if not specified
    -f, --follow-symlink       follow links, otherwise fail with file not found
    -d, --debug                enable to show error messages
    -n, --not-found <filename> the error 404 file
    -c, --cors <pattern>       Cross Origin Pattern. Use "*" to allow all origins
    -z, --no-nocache           disable cache (http 304) responses.
    -o, --open                 open server in the local browser

## Using as a node module

The server may be used as a dependency HTTP server.

### Example

```javascript
var StaticServer = require('static-server');
var server = new StaticServer({
  rootPath: '.',            // required, the root of the server file tree
  port: 1337,               // required, the port to listen
  name: 'my-http-server',   // optional, will set "X-Powered-by" HTTP header
  host: '10.0.0.100',       // optional, defaults to any interface
  cors: '*',                // optional, defaults to undefined
  followSymlink: true,      // optional, defaults to a 404 error
  templates: {
    index: 'foo.html',      // optional, defaults to 'index.html'
    notFound: '404.html'    // optional, defaults to undefined
  }
});

server.start(function () {
  console.log('Server listening to', server.port);
});

server.on('request', function (req, res) {
  // req.path is the URL resource (file name) from server.rootPath
  // req.elapsedTime returns a string of the request's elapsed time
});

server.on('symbolicLink', function (link, file) {
  // link is the source of the reference
  // file is the link reference
  console.log('File', link, 'is a link to', file);
});

server.on('response', function (req, res, err, file, stat) {
  // res.status is the response status sent to the client
  // res.headers are the headers sent
  // err is any error message thrown
  // file the file being served (may be null)
  // stat the stat of the file being served (is null if file is null)

  // NOTE: the response has already been sent at this point
});
```

## FAQ
* _Can I use this project in production environments?_ **Obviously not.**
* _Can this server run php, ruby, python or any other cgi script?_ **No.**
* _Is this server ready to receive thousands of requests?_ **Preferably not.**

## Contributors
An special thank you to [all contributors](https://github.com/nbluis/static-server/graphs/contributors) who allow this project to continue to evolve.

## License
[The MIT License (MIT)](http://creativecommons.org/licenses/MIT/)

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