simple development http server with live reload capability
There are two reasons for using this:
You don't need to install any browser plugins or manually add code snippets to your pages for the reload functionality to work, see "How it works" section below for more information. If you don't want/need the live reload, you should probably use something even simpler, like the following Python-based one-liner:
python -m SimpleHTTPServer
You need node.js and npm. You should probably install this globally.
npm install -g live-server
git clone https://github.com/tapio/live-server cd live-server npm install # Local dependencies if you want to hack npm install -g # Install globally
Issue the command
live-server in your project's directory. Alternatively you can add the path to serve as a command line parameter.
This will automatically launch the default browser. When you make a change to any file, the browser will reload the page - unless it was a CSS file in which case the changes are applied without a reload.
Command line parameters:
--port=NUMBER- select port to use, default: PORT env var or 8080
--host=ADDRESS- select host address to bind to, default: IP env var or 0.0.0.0 ("any address")
--no-browser- suppress automatic web browser launching
--browser=BROWSER- specify browser to use instead of system default
--quiet- suppress logging
--open=PATH- launch browser to PATH instead of server root
--watch=PATH- comma-separated string of paths to exclusively watch for changes (default: watch everything)
--ignore=PATH- comma-separated string of paths to ignore
--ignorePattern=RGXP- Regular expression of files to ignore (ie
--entry-file=PATH- serve this file in place of missing files (useful for single page apps)
--mount=ROUTE:PATH- serve the paths contents under the defined route (multiple definitions possible)
--spa- translate requests from /abc to /#/abc (handy for Single Page Apps)
--wait=MILLISECONDS- wait for all changes, before reloading
--htpasswd=PATH- Enables http-auth expecting htpasswd file located at PATH
--cors- Enables CORS for any origin (reflects request origin, requests with credentials are supported)
--https=PATH- PATH to a HTTPS configuration module
--help | -h- display terse usage hint and exit
--version | -v- display version and exit
If a file
~/.live-server.json exists it will be loaded and used as default options for live-server on the command line. See "Usage from node" for option names.
var liveServer = ;var params =port: 8181 // Set the server port. Defaults to 8080.host: "0.0.0.0" // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.root: "/public" // Set root directory that's being server. Defaults to cwd.open: false // When false, it won't load your browser by default.ignore: 'scss,my/templates' // comma-separated string for paths to ignorefile: "index.html" // When set, serve this file for every 404 (useful for single-page applications)wait: 1000 // Waits for all changes, before reloading. Defaults to 0 sec.mount: '/components' './node_modules' // Mount a directory to a route.logLevel: 2 // 0 = errors only, 1 = some, 2 = lots;liveServerstartparams;
In order to enable HTTPS support, you'll need to create a configuration module.
The module must export an object that will be used to configure a HTTPS server.
The keys are the same as the keys in
options for tls.createServer.
var fs = ;moduleexports =cert: fskey: fspassphrase: "12345";
Open your browser's console: there should be a message at the top stating that live reload is enabled. Note that you will need a browser that supports WebSockets. If there are errors, deal with them. If it's still not working, file an issue.
We welcome contributions! See CONTRIBUTING.md for details.
--spacli option for single page apps, translates requests from /abc to /#/abc (@evanplaice)
IPenv var for default host (@dotnetCarpenter)
ignorePatternfrom config file (@cyfersystems)
--quietnow silences warning about injection failure
--watchpaths now disables adding mounted paths to watching
--ignorePattern=RGXPexclude files from watching by regexp (@psi-4ward)
--watch=PATHcli option to only watch given paths
--mount=ROUTE:PATHcli option to specify alternative routes to paths (@pmentz)
--browser=BROWSERcli option to specify browser to use (@sakiv)
~/.live-server.jsonif exists (@mikker)
--port=0to select random port (@viqueen)
--version / -vcommand line flags to display version
--hostcli option to mirror the API parameter
--ignore=PATHcli option to not watch given server root relative paths (@richardgoater)
--entry-file=PATHcli option to specify file to use when request is not found (@izeau)
--wait=MSECScli option to wait specified time before reloading (@leolower, @harrytruong)
logLevelparameter in library to control amount of console spam
--quietcli option to suppress console spam
--open=PATHcli option to launch browser in specified path instead of root (@richardgoater)
noBrowser: trueoption is deprecated in favor of
--no-browsercommand line flag to suppress browser launch
--helpcommand line flag to display usage
Copyright (c) 2012 Tapio Vierros
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.