Zero dependency dev server
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vscode
examples
src
test/server
.gitignore
.npmrc
.travis.yml
LICENSE.md
README.md
package.json
pre-flight-tests

README.md

srvs serves modern webapps for dev, with none of the fat

Build Status codecov npm

srvs is a zero dependency dev server with support for static content in addition to JavaScript modules hosted from local files and unpkg.com.

Installation

Global

npm i -g srvs

Then you may run with:

srvs

npx

No install required, just run:

npx srvs

Keep in mind that in order to use npx with Node.js < 8 you need to either install npx globally:

npm i -g npx

or update your version of npm:

npm i -g npm

Local

Install with npm / Yarn:

npm i -D srvs

Then add srvs to the scripts in your package.json:

"scripts": {
  "start": "srvs"
}

Now you may run with:

npm start

Usage

Command Line

Here are the available command line arguments:

Argument Usage Default
port The port on which the dev server will listen. 8080
docRoot The relative path from which static assets such as index.html will be served. public
scriptRoot The relative path from which local JavaScript modules will be served. src
hot Watches for changes in your script files. Listen in your app with module.hot.accept. false

Each argument is passed in the form --argument=value. Here is an example using all available arguments:

npx srvs --port=3000 --root=~/myapp --docRoot=static --scriptRoot=js --hot

API

srvs offers a programmatic way to integrate running with existing JavaScript code.

You may bring in the srvs API function using import if you have support for ES6 syntax:

import srvs from "srvs";

srvs(options).then(config => {
  // dev server is now open for business
});

Or using require:

const srvs = require("srvs");

srvs(options).then(config => {
  // dev server is now open for business
});

The options object has the same properties and values as the arguments supported by the command line version. The config parameter provided to the resolved Promise has the same properties as options.

Caveats

  • This is only for use as a development tool, please do not use in production.
  • If you intend to use dynamic import (as the examples/hot project does) to hot reload changed modules, be aware this is not supported by some browsers.

License

srvs is MIT licensed. See LICENSE.