0.1.2 • Published 3 years ago

@lencse/cliserver v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

CLIserver

Node.js CI npm Coverage Status Maintainability Rating

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 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

Prerequisites

Installation

Using npx

You can use CLIserver directly with npx.

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

Global installation

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.

npm install --save-dev @lencse/cliserver

package.json:

{
    // ...
    "scripts": {
        "dev": "cliserver serve . -l"
    }
}
npm run dev

Usage

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

Help

Show the help.

cliserver --help

Serve

Start a static webserver from a directory.

cliserver serve [directory]

Arguments:

ShortLongTypeDefaultDescription
-p--portnumber7100Port where the server is listening
-l--livereloadbooleanfalseReload page in the browser on file changes
-o--livereloadPortnumber35729Port where the livereload server is listening
-f--listenerFilesarray \<DIRECTORY>/index.html List of HTML files to reload on file changes
-w--watcharray \<DIRECTORY> Watch changes in files and directories
-r--rootstring\<DIRECTORY>/index.htmlDefault file to serve on the / route
-d--delaynumber250Livereload delay on file file changes (millisecs)

Examples

Basic usage: start a static webserver from a directory on the default port (7100)
cliserver serve ~/website
Start a server on port 8000 with livereload
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.

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 for the static server and 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:

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 frameworks or check some awesome 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