# handydevserver

> A simple web server with handy hooks for setting up test environments for web development.

Latest version **1.0.9** (published 2018-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install handydevserver
pnpm add handydevserver
yarn add handydevserver
bun add handydevserver
```

## 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 | 1.0.9 |
| Published | 2018-03-13 |
| First published | 2015-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 24.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexei White |
| Maintainers | alexei.white |
| Keywords | dev, debug, web, server, node |

## Links

- npm: https://www.npmjs.com/package/handydevserver
- Repository: https://github.com/alexsaves/handydevserver
- Homepage: https://github.com/alexsaves/handydevserver#readme
- Issues: https://github.com/alexsaves/handydevserver/issues
- npm.io page: https://npm.io/package/handydevserver

## Dependencies (4)

- [pem](https://npm.io/package/pem.md) ^1.9.7
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [strftime](https://npm.io/package/strftime.md) ^0.10.0
- [app-root-dir](https://npm.io/package/app-root-dir.md) ^1.0.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2018-03-13
- 1.0.8 — 2017-08-14
- 1.0.7 — 2017-01-09
- 1.0.6 — 2017-01-07
- 1.0.5 — 2017-01-06
- 1.0.4 — 2016-10-25
- 1.0.3 — 2016-08-10
- 1.0.1 — 2016-07-14
- 1.0.0 — 2016-02-01
- 0.2.1 — 2016-01-08
- 0.2.0 — 2015-11-12
- 0.1.1 — 2015-09-15
- 0.1.0 — 2015-09-15
- 0.0.9 — 2015-08-31
- 0.0.8 — 2015-08-25
- … 6 more at https://npm.io/package/handydevserver/versions

## README

HandyDevServer
===================
A simple web server with handy hooks for setting up test environments for web development.
###Installation &nbsp;  [![npm version](https://badge.fury.io/js/handydevserver.svg)](http://badge.fury.io/js/handydevserver)
```sh
npm install handydevserver
```
###Simple Usage
Call the constructor with a port to run on, and an array of folders to look for files in.
```javascript
var handydevserver = require("handydevserver");
// Add three folders to the common directory.
// Run on port 8080
handydevserver(8080, ['./dist', './smoketest', './gateway'])
```
###Simulated server delay
To simulate latency, add a ``latency`` attribute with a delay value (in ms):
```javascript
handydevserver(8080, ['./dist', './smoketest', './gateway'], {
    latency: 2500
})
```
If you want to randomize the latency, provide an array of two values and the latency will be randomized somewhere in between:
```javascript
handydevserver(8080, ['./dist', './smoketest', './gateway'], {
    latency: [500, 2500]
})
```
###Ignore files/folders
To remove certain files or folders for directory listings, add an ``ignore`` array of strings. These are wildcards, so if you specify the string "hello" it would ignore things like: "hello_world", "hello_america", etc:
```javascript
handydevserver(8080, ['./dist', './smoketest', './gateway'], {
    ignore: ['node_modules', '.svn']
})
```
###Hooks
You can intercept text files (CSS, HTML, JS, etc) before they get delivered to the browser incase you want to change them. To do this, pass a config object to your call to the constructor:
```javascript
handydevserver(
    8080,
   ['./dist', './smoketest', './gateway'],
    {
      ontextfile: function (filename, contents, headers) {
        if (filename.indexOf('gateway.js') || filename.indexOf('gateway.min.js')) {
          contents = contents.replace(/foo/gi, "bar");
        }
        // Add some header
        headers.myHeader = 'some header value';
        return contents;
      },
      onhtmlfile: function(filename, contents, headers) {
        // an HTML file is being served
        // Do whatever changes you want
        return contents;
      },
      onjsfile: function(filename, contents, headers) {
        // a JavaScript file is being served
        // Do whatever changes you want
        return contents;
      }
    });
```
###Custom Headers
You can add your own custom headers to responses by adding a ``headers`` object to your configuration:
```javascript
handydevserver(
    8080,
   ['./dist', './smoketest', './gateway'],
    {
      headers: {'mycustomheader':'somevalue'}
    });
```
###SSL
You can also run an HTTPS server by using the self-signed cert feature. Note: you will need to add an exception to any certificate errors that occur in your browser.
```javascript
handydevserver(443, [/*dirs*/], { ssl: true });
```

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