livereload2 v1.0.1
node-livereload
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.
This is an alternative version of node-livereload, will remove it when the origin package is updated.
Example Usage
First, install the LiveReload browser plugins by visiting http://help.livereload.com/kb/general-use/browser-extensions.
To use livereload from the command line:
$ npm install -g livereload2
$ livereload [path]For options: $ livereload --help
Or to use the api within a project:
$ npm install livereloadThen, simply create a server and fire it up.
livereload = require('livereload');
server = livereload.createServer();
server.watch(__dirname + "/public");You can also use this with a Connect server:
connect = require('connect');
connect.createServer(
connect.compiler({ src: __dirname + "/public", enable: ['less'] }),
connect.staticProvider(__dirname + "/public")
).listen(3000);
livereload = require('livereload');
server = livereload.createServer({exts: ['less']});
server.watch(__dirname + "/public");Options
The createServer() method supports a few basic options, passed as a JavaScript object:
portis the listening port. It defaults to35729which is what the LiveReload extensions use currently.extsis an array of extensions you want to observe. The default extensions arehtml,css,js,png,gif,jpg,php,php5,py,rb, anderbapplyJSLivetells LiveReload to reload JavaScript files in the background instead of reloading the page. The default for this isfalse.applyCSSLivetells LiveReload to reload CSS files in the background instead of refreshing the page. The default for this istrue.exclusionslets you specify files to ignore. By default, this includes.git/,.svn/, and.hg/aliaslets you specify file extensions to be aliased. By default, this maps.stylto.css, by which, changing.stylfile never fires full page reload.delaydelay in ms before refresh (default: 50)
Trigger refresh programmatically
The server is listening for post request on "/reload".
request = require('request');
request.post('http://localhost:35729/reload');Limitations
Right now this is extremely simple. It relies on polling so there's a delay in refreshing the browser. It could be faster.
License
Copyright (c) 2010-2012 Joshua Peek and Brian P. Hogan.
Released under the MIT license. See LICENSE for details.