# @lencse/cliserver

> [![Node.js CI](https://github.com/lencse/cliserver/actions/workflows/default.yml/badge.svg)](https://github.com/lencse/cliserver/actions) [![npm](https://img.shields.io/npm/v/@lencse/cliserver)](https://www.npmjs.com/package/@lencse/cliserver) [![Coverage

Latest version **0.1.2** (published 2021-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lencse/cliserver
pnpm add @lencse/cliserver
yarn add @lencse/cliserver
bun add @lencse/cliserver
```

Provides the command `cliserver`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2021-05-01 |
| First published | 2021-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 55.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Lencse |
| Maintainers | lencse |
| Keywords | server, static server, livereload, cli, command line |

## Links

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

## Dependencies (9)

- [koa](https://npm.io/package/koa.md) ^2.13.1
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [yargs](https://npm.io/package/yargs.md) ^16.2.0
- [cli-table](https://npm.io/package/cli-table.md) ^0.3.6
- [koa-logger](https://npm.io/package/koa-logger.md) ^3.2.1
- [koa-router](https://npm.io/package/koa-router.md) ^10.0.0
- [koa-static](https://npm.io/package/koa-static.md) ^5.0.0
- [livereload](https://npm.io/package/livereload.md) ^0.9.3
- [expand-tilde](https://npm.io/package/expand-tilde.md) ^2.0.2

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2021-05-01
- 0.1.1 — 2021-05-01
- 0.1.0 — 2021-05-01

## README

# CLIserver

[![Node.js CI](https://github.com/lencse/cliserver/actions/workflows/default.yml/badge.svg)](https://github.com/lencse/cliserver/actions)
[![npm](https://img.shields.io/npm/v/@lencse/cliserver)](https://www.npmjs.com/package/@lencse/cliserver)
[![Coverage Status](https://coveralls.io/repos/github/lencse/cliserver/badge.svg?branch=main)](https://coveralls.io/github/lencse/cliserver?branch=main)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=lencse_cliserver&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=lencse_cliserver)

CLIserver is a command line tool to run a local web server from a static directory and see the file changes without manually reloading the browser. Enjoy the [livereload ](http://livereload.com/) functionality without robust frameworks like AngularJS, Webpack or ReactJS.

With CLIserver, there's no need to install anything in the project or to change a single line of code in the source files.

![A quick demo about CLIserver](.github/cliserver.gif)

## Prerequisites

* [`node.js`](https://nodejs.org/) (v10 or higher)

## Installation

### Using npx

You can use CLIserver directly with [`npx`](https://www.npmjs.com/package/npx).

```sh
npx -p @lencse/cliserver cliserver serve . -l
```

### Global installation

```sh
npm install -g @lencse/cliserver
cliserver serve . -l
```

### Local installation

In a `node.js` project you can install CLIserver locally and include it in your [development scripts](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#scripts).

```sh
npm install --save-dev @lencse/cliserver
```

`package.json`:

```js
{
    // ...
    "scripts": {
        "dev": "cliserver serve . -l"
    }
}
```

```sh
npm run dev
```

## Usage

CLIserver is a command line tool with the following available commands:

### Help

Show the help.

```sh
cliserver --help
```

### Serve

Start a static webserver from a directory.

```sh
cliserver serve [directory]
```

#### Arguments:

| Short | Long | Type | Default | Description |
|---|---|---|---|---|
| `-p` | `--port` | number | 7100 | Port where the server  is listening |
| `-l` | `--livereload` | boolean | false | Reload page in the browser on file changes |
| `-o` | `--livereloadPort` | number | 35729 | Port where the livereload server is listening |
| `-f` | `--listenerFiles` | array | [ \<DIRECTORY\>/index.html ] | List of HTML files to reload on file changes |
| `-w` | `--watch` | array | [ \<DIRECTORY\> ] | Watch changes in files and directories |
| `-r` | `--root` | string | \<DIRECTORY\>/index.html | Default file to serve on the `/` route |
| `-d` | `--delay` | number | 250| Livereload delay on file file changes (millisecs) |

#### Examples

##### Basic usage: start a static webserver from a directory on the default port (`7100`)

```sh
cliserver serve ~/website
```

##### Start a server on port `8000` with livereload

```sh
cliserver serve ~/website -p 8000 -l
```

##### A complex example

Start a server on port `8000`, livereload is listening on port `35600`, 3 files are being reloaded on changes, but only on updates in the `css` or `img` directories, the server root is `default.html` and the livereload delay is 250 ms.

```sh
cliserver serve ~/website -p 8000 -l -o 35600 \
    -f ~/website/default.html -f ~/website/about.html -f ~/website/contact.html \
    -w ~/website/css -w ~/website/img \
    -r ~/website/default.html \
    -d 250
```

## Under the hood

CLIserver uses [Koa](https://koajs.com/) for the static server and [node-livereload](https://github.com/napcs/node-livereload) for livereloading.

## Alternatives

If you have `python` and don't need livereload, you don't have to install CLIserver. A good one-liner alternative to start a `HTTP` server from the current directory:

```sh
python3 -m http.server
```

## 🚫 Warning: do not use it in production

Please keep in mind that CLIserver is meant to be a small and quick development tool to speed up the feedback cycle when building static websites. Error handling, monitoring and performance optimalization is completely out of scope in this project.

To host a static website, consider using one of the [great](https://expressjs.com/) [frameworks](https://www.npmjs.com/package/koa-static) or check some [awesome](https://www.netlify.com/) hosting providers on the market.

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

[MIT](https://choosealicense.com/licenses/mit/)

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