@lencse/cliserver v0.1.2
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 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.
Prerequisites
node.js
(v10 or higher)
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:
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
)
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.