# @gustavnikolaj/server-helper

> Resolve configuration and restart server on changes.

Latest version **3.2.0** (published 2020-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gustavnikolaj/server-helper
pnpm add @gustavnikolaj/server-helper
yarn add @gustavnikolaj/server-helper
bun add @gustavnikolaj/server-helper
```

Provides the command `server-helper`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2020-02-23 |
| First published | 2018-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 19.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gustav Nikolaj Olsen |
| Maintainers | gustavnikolaj |

## Links

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

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^7.1.3
- [semver](https://npm.io/package/semver.md) ^7.1.3
- [getopts](https://npm.io/package/getopts.md) ^2.2.5
- [invariant](https://npm.io/package/invariant.md) ^2.2.2
- [read-pkg-up](https://npm.io/package/read-pkg-up.md) ^7.0.0

## Recent versions

- 3.2.0 (latest) — 2020-02-23
- 3.1.0 — 2020-02-23
- 3.0.3 — 2019-12-05
- 3.0.2 — 2019-12-04
- 3.0.1 — 2019-12-04
- 3.0.0 — 2019-12-04
- 3.0.0-0 — 2019-12-04
- 2.2.0 — 2019-11-21
- 2.1.0 — 2019-01-26
- 2.0.6 — 2018-06-14
- 2.0.5 — 2018-05-13
- 2.0.4 — 2018-05-13
- 2.0.3 — 2018-05-13
- 2.0.2 — 2018-05-13
- 2.0.1 — 2018-05-13
- … 1 more at https://npm.io/package/@gustavnikolaj/server-helper/versions

## README

# server helper

[![npm version](https://badge.fury.io/js/%40gustavnikolaj%2Fserver-helper.svg)](https://www.npmjs.com/package/@gustavnikolaj/server-helper)
[![Build Status](https://travis-ci.com/gustavnikolaj/server-helper.svg?branch=master)](https://travis-ci.com/gustavnikolaj/server-helper)

Simple node.js server helper module.

- It will run your server, and allow you to have a clean main application file,
  which won't be cluttered with bootstrap code.
- It can be used to restart your server on file change for a nice development
  experience.

## Example

```js
// app.js

const express = require("express");

module.exports = function appFactory() {
  const app = express();

  app.get("/", (req, res, next) => {
    res.send(`Hello, world!`);
  });

  return app;
};
```

```
$ server-helper app.js
```

## CLI Options

- `--watch` / `-w`: Enable automatic restarting on file changes.
- `--port` / `-p`: Change the port number. [Default: 3000]
- `--host` / `-h`: Change the host.

## Programmatic use:

```js
// start.js

const serverHelper = require("@gustavnikolaj/server-helper");

serverHelper({
  entrypoint: require.resolve("./app.js"),
  port: 5000
});
```

```
$ node start.js
```

The command line flags are still supported.

## Config

Configuration can be given in multiple different ways, to support different
use-cases. See
[doc/background/configuration.md](doc/background/configuration.md).

Options given as cli flags are used before options given as environment
variables, which are used before options given in the programmatic interface.

### Configuration through cli flags

- `--watch` / `-w`: Enable automatic restarting on file changes.
- `--port` / `-p`: Change the port number. [Default: 3000]
- `--host` / `-h`: Change the host.

The path to the entrypoint file is given as the only non-flag argument.

### Configuration through environment variables.

Configuration can also be passed through environment variables.

- `PORT`: The port number to listen to.
- `SERVERHELPER_PORT`: Same as `PORT`, but higher specificity.
- `SERVERHELPER_HOST`: What host to bind to.

### Configuration through options in api mode

You call serverHelper with an options object as the only argument. This can only
be done when invoking it programatically.

Supported properties:

- `entrypoint`: The path to the file that implements the server handler.
- `port`: The port number to listen to. (number)
- `host`: The host to bind to. (string)
- `watch`: Enables watch mode. (boolean)

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