Node.js module to refresh and reload your code in your browser when your code changes. No browser plugins required.
Automatically refresh and reload your code in your browser when your code changes. No browser plugins required.
Restarting your HTTP server and refreshing your browser is annoying.
Reload works in two different ways depending on if you're using it:
reload-client.jsto the browser.
Once reload-server and reload-client are connected, the client side code opens a WebSocket to the server and waits for the WebSocket to close, once it closes, reload waits for the server to come back up (waiting for a socket on open event), once the socket opens we reload the page.
npm install [-g] [--save-dev] reload
There are two different ways to use reload.
When used with Express reload creates a new Express route for reload. When you restart the server, the client will detect the server being restarted and automatically refresh the page.
var express =var http =var path =var reload =var bodyParser =var logger =var app =var publicDir = pathappappapp //parses json, multi-part (file), url-encodedappvar server = http// Reload code hereserver;
Reload Express Sample AppReload Express Sample App12<!-- All you have to do is include the reload script and have it be on every page of your project -->
Refer to the reload express sample app for this working example.
You can manually call a reload event by calling
reload() yourself. An example is shown below:
reloadServer = ;watch;
reload(httpServer, expressApp, [verbose])
httpServer: The Node.js http server from the module
expressApp: The express app. It may work with other frameworks, or even with Connect. At this time, it's only been tested with Express.
verbose: If set to true, will show logging on the server and client side
There are two ways to use the command line application.
Each will require different modes of installing.
In case one you should install reload globally with
npm install reload -g. Also with reload installed globally you can go to any directory with an HTML file and use the command reload to constantly watch it and reload it while you make changes.
In case two you should install locally with
npm install --save-dev, since this tool is to aid in development you should install it as a dev dependency.
Navigate to your html directory:
This will open your
index.html file in the browser. Any changes that you make will now reload in the browser. You don't need to modify your HTML at all.
Usage: reload [options]Options:-h, --help Output usage information-V, --version Output the version number-b, --browser Open in the browser automatically.-n, --hostname If -b flag is being used, this allows for custom hostnames. Defaults to localhost.-d, --dir [dir] The directory to serve up. Defaults to current dir.-e, --exts [extensions] Extensions separated by commas or pipes. Defaults to html,js,css.-p, --port [port] The port to bind to. Can be set with PORT env variable as well. Defaults to 8080-s, --start-page [start-page] Specify a start page. Defaults to index.html.-v, --verbose Turns on logging on the server and client side. Defaults to false.
Copyright 2016, JP Richardson email@example.com