Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @m59/reload-server with all npm packages installed. Try it out:

var reloadServer = require("@m59/reload-server")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@m59/reload-server v1.0.6

Simple SPA development server with reload API. Injects reload script.

Reload Server

Simple SPA development server with reload API. Injects reload script.

Install

npm install @m59/reload-server

CLI

m59-reload-server [options]
  -h, --help          output usage information
  -V, --version       output the version number
  -d, --dir  [value]  directory of files to be served [cwd]
  -p, --port [value]  `port` argument for server.listen() [8080]
  -H, --host [value]  `host` argument for server.listen()
  -q, --quiet         disable logging
  --wsPath   [value]  path to the websocket server

JS API

const Server = require('@m59/reload-server')

const server = Server({
  dir: './www'
})
server.listen(8080)

watch(someFiles, function(event) {
  server.reload(event.path) // smart reload based on path
})

Server(options)

  • options: object
    • dir: string, cwd
    • wsPath: string, random
    • quiet: boolean, false
  • returns: server

server.reload(path)

Signals connected clients to reload the page. If path is given, clients may be signaled to refresh CSS or images based on the file extension in the path, rather than reloading the page.

server.refreshCSS()

Signals connected clients to refresh CSS without page reload.

server.refreshImages()

Signals connected clients to refresh images without page reload.

server.wsPath

The path to the websocket server.

server.wss

The ws server.

HTTP API

POST /reload
POST /reload/css
POST /reload/img

The path parameter of server.reload can be passed as JSON in the body or as a query parameter.

{"path": "/path/here.css"}

/reload?path=/path/here.css

curl -X POST http://localhost:8080/reload

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free