-
Notifications
You must be signed in to change notification settings - Fork 4
Examples
Eric M. Dantas edited this page May 16, 2018
·
10 revisions
A bunch of examples demonstrating how to use aliv, from the CLI to a simple node module.
$ aliv --port 9999 --pathIndex src --only src$ aliv{
"port": 9999,
"pathIndex": "src",
"only": src
} "use strict";
// pull the dependency
const Server = require('aliv');
// start server
let _aliv = new Server({quiet: true});
_aliv.start();
_aliv.on('client-connected', () => {
// client connected
});
_aliv.on('file-changed', (info) => {
// file changed, info.path
});
_aliv.on('browser-open', (info) => {
// browser open called
});
_aliv.on('reload', () => {
// reload called
});"use strict";
// pull the dependency
const Server = require('aliv');
// start server
let _aliv = new Server({quiet: true});
_aliv.use((done) => {
// do something
done()
})
_aliv.use((done) => {
setTimeout(() => {
// does something else
done()
}, 1000)
})
_aliv.start();"use strict";
const gulp = require('gulp');
// pull the dependency
const Server = require('aliv');
// grab the instance of the server
let _aliv = new Server({quiet: true, port: 1234});
gulp.task('default', () => {
// when the user runs 'gulp', we start the server
// and the file changes that happen will trigger the browser
// reload automatically
_aliv.start();
});"use strict";
const gulp = require('gulp');
// pull the dependency
const Server = require('aliv');
// grab the instance of the server
let _aliv = new Server({quiet: true, port: 1234, watch: false});
gulp.task('reload', () => {
// reload the browsers
_aliv.reload();
});
gulp.task('default', () => {
// when the user runs 'gulp', we start the server
_aliv.start();
// we call the 'reload' task everytime a css, js or html changes
// based on gulp's implementation
gulp.watch(['**/*.js', '**/*.css', '**/*.html'], ['reload']);
});