An implementation of the LiveReload server in Node.js. It's an alternative to the graphical http://livereload.com/ application, which monitors files for changes and reloads your web browser.
You can use this by either adding a snippet of code to the bottom of your HTML pages or install the Browser Extensions.
Install the LiveReload browser plugins by visiting http://help.livereload.com/kb/general-use/browser-extensions.
Only Google Chrome supports viewing
file:/// URLS, and you have to specifically enable it. If you are using other browsers and want to use
file:/// URLs, add the JS code to the page as shown in the next section.
Add this code:
Note: If you are using a different port other than
35729 you will
need to change the above script.
You can run LiveReload two ways:
To use livereload from the command line:
$ npm install -g livereload$ livereload [path]
To use the api within a project:
$ npm install livereload
Then, create a server and fire it up.
var livereload = ;var server = livereload;server;
You can also use this with a Connect server. Here's an example of a simple server
connect and a few other modules just to give you an idea:
var connect = ;var compiler = ;var static = ;var server = ;server;server;server;var livereload = ;var lrserver = livereload;lrserver;
You can then start up the server which will listen on port
Passing an array of paths or glob patterns will allow you to watch multiple directories. All directories have the same configuration options.
$ livereload "path1, path2, path3"
// server.jsvar server = livereload;server;
Then run the server:
$ node server.js
Then, assuming your HTML file has a stylesheet link like this:
<!-- html -->
/User/Workspace/test/css/style.css is modified, the stylesheet will be reload.
The commandline options are
--portto specify the listening port
--debugto show debug messages when the browser reloads.
--extsto include additional extentions that you want to observe. An example being -e 'jade scss'.
--usepollingto poll for file system changes. Set this to true to successfully watch files over a network.
--waitto add a delay (in miliseconds) between when livereload detects a change to the filesystem and when it notifies the browser
Specify the path when using the options.
$ livereload . -w 1000 -d
createServer() method accepts two arguments.
httpsis an optional object of options to be passed to https.createServer (if not provided,
http.createServeris used instead)
portis the listening port. It defaults to
35729which is what the LiveReload extensions use currently.
extsis an array of extensions you want to observe. The default extensions are
erb, and "coffee."
applyCSSLivetells LiveReload to reload CSS files in the background instead of refreshing the page. The default for this is
applyImgLivetells LiveReload to reload image files in the background instead of refreshing the page. The default for this is
true. Namely for these extensions: jpg, jpeg, png, gif
exclusionslets you specify files to ignore. By default, this includes
originalPathSet URL you use for development, e.g 'http:/domain.com', then LiveReload will proxy this url to local path.
overrideURLlets you specify a different host for CSS files. This lets you edit local CSS files but view a live site. See http://feedback.livereload.com/knowledgebase/articles/86220-preview-css-changes-against-a-live-site-then-uplo for details.
usePollingPoll for file system changes. Set this to
trueto successfully watch files over a network.
delayadd a delay (in miliseconds) between when livereload detects a change to the filesystem and when it notifies the browser. Useful if the browser is reloading/refreshing before a file has been compiled, for example, by browserify.
trueto indicate that the websocket server should not be started automatically. (useful if you want to start it yourself later)
The second argument is an optional
callback that will be sent to the LiveReload server and called for the
listening event. (ie: when the server is ready to start accepting connections)
Older version history not kept.
Copyright (c) 2010-2016 Brian P. Hogan and Joshua Peek
Released under the MIT license. See
LICENSE for details.