BrowserSync allows to automatically reload in the browser web resources: HTML file, CSS, JavaScript … Here’s how to run browser-sync quickly, on the command line, in the case of a local or global installation.
- Requirements :
- Install Node.js and npm
Local installation
From the web project folder to synchronize, install browser-sync locally:
npm install browser-sync
The executable is in a subfolder of the project:
./node_modules/.bin/browser-sync
Example from a Windows command prompt (the current folder is the project where the web resources are located):
node_modules\.bin\browser-sync start --server --files ["* .html", "* .css", "* .js"]
Global installation
From any location, globally install browser-sync:
npm install -g browser-sync
A global installation, unlike a local installation, exposes the browser-sync package and executable on the entire machine.
The package is then available from the root of any project, by launching:
browser-sync start --server --files ["* .html", "* .css", "* .js"]
Using synchronization
Open in a browser http://localhost:3000/
.
Behind this URL, all project files are exposed, and all .html
, .css
, and .js
will be reloaded as soon as they are modified.