simple development http server with live reload capability
There are two reasons for using this:
If you don't want/need the live reload, you should probably use something 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 (you should have
index.html present). 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.
You can configure the port to be used by the server by adding the
--port=<number> runtime option when invoking live-server, or by setting the
PORT environment variable prior to running live-server.
--no-browser- suppress automatic web browser launching
--quiet- suppress logging
--open=PATH- launch browser to PATH instead of server root
var liveServer = require"live-server";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.root: "/public" // Set root directory that's being server. Defaults to cwd.open: false // When false, it won't load your browser by default.;liveServerstartparams;
Open your browser's console: there should be a message at the top stating that live reload is enabled. If there are errors, deal with them. You will need a browser that supports WebSockets.
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.