Gathering detailed insights and metrics for tiny-lr
Gathering detailed insights and metrics for tiny-lr
Gathering detailed insights and metrics for tiny-lr
Gathering detailed insights and metrics for tiny-lr
npm install tiny-lr
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
424 Stars
258 Commits
90 Forks
8 Watching
11 Branches
48 Contributors
Updated on 02 Sept 2023
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-2.5%
137,281
Compared to previous day
Last week
4.1%
769,499
Compared to previous week
Last month
26.1%
3,049,423
Compared to previous month
Last year
7.5%
36,150,294
Compared to previous year
This script manages a tiny LiveReload server implementation.
It exposes an HTTP server and express middleware, with a very basic REST API to notify the server of a particular change.
It doesn't have any watch ability, this must be done at the build process or application level.
Instead, it exposes a very simple API to notify the server that some changes have been made, then broadcasted to every connected livereload client.
# notify of a single change
curl http://localhost:35729/changed?files=style.css
# notify using a longer path
curl http://localhost:35729/changed?files=js/app.js
# notify of multiple changes, comma or space delimited
curl http://localhost:35729/changed?files=index.html,style.css,docs/docco.css
Or you can bulk the information into a POST request, with the body as a JSON array of files.
curl -X POST http://localhost:35729/changed -d '{ "files": ["style.css", "app.js"] }'
# from a JSON file
node -pe 'JSON.stringify({ files: ["some.css", "files.css"] })' > files.json
curl -X POST -d @files.json http://localhost:35729
As for the livereload client, you need to install the browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions- (note: you need to listen on port 35729 to be able to use it with your browser extension)
or add the livereload script tag manually: http://feedback.livereload.com/knowledgebase/articles/86180-how-do-i-add-the-script-tag-manually- (and here you can choose whichever port you want)
The best way to integrate the runner into your workflow is to add it as a reload
step within your build tool.
1var tinylr = require('tiny-lr'); 2 3// standard LiveReload port 4var port = 35729; 5 6// tinylr(opts) => new tinylr.Server(opts); 7tinylr().listen(port, function() { 8 console.log('... Listening on %s ...', port); 9})
You can define your own route and listen for a specific request:
1var server = tinylr(); 2 3server.on('GET /myplace', function(req, res) { 4 res.write('Mine'); 5 res.end(); 6})
And stop the server manually:
1server.close();
This will close any websocket connection established and emit a close event.
To use as a connect / express middleware, tiny-lr needs query / bodyParser middlewares prior in the stack (to handle POST requests)
Any handled requests ends at the tinylr level, not found and errors are nexted to the rest of the stack.
1var port = process.env.LR_PORT || process.env.PORT || 35729; 2 3var path = require('path'); 4var express = require('express'); 5var tinylr = require('tiny-lr'); 6var body = require('body-parser'); 7 8var app = express(); 9 10// This binds both express app and tinylr on the same port 11 12app 13 .use(body()) 14 .use(tinylr.middleware({ app: app })) 15 .use(express.static(path.resolve('./'))) 16 .listen(port, function() { 17 console.log('listening on %d', port); 18 });
The port you listen on is important, and tinylr should always listen on
the LiveReload standard one: 35729
. Otherwise, you won't be able to rely
on the browser extensions, though you can still use the manual snippet
approach.
You can also start two different servers, one on your app port, the other listening on the LiveReload port.
Head over to https://github.com/gruntjs/grunt-contrib-watch
See the make-livereload repo. This repository defines a bin wrapper you can use and install with:
npm install make-livereload -g
It bundles the same bin wrapper previously used in the tiny-lr repo.
Usage: tiny-lr [options]
Options:
-h, --help output usage information
-V, --version output the version number
port -p
pid Path to the generated PID file (default: ./tiny-lr.pid)
See the gulp-livereload repo.
livereload
- Path to the client side lib (defaults to path.join(__dirname, '../node_modules/livereload-js/dist/livereload.js')
)port
- Livereload port (defaults to 35729
)errorListener
- A callback to invoke when an error occurs (otherwise, fallbacks to standard error output)handler
- A function to use as the main request handler (function(req, res)
). When not defined, the default handler takes place.app
- An express or other middleware based HTTP serverkey
- Option to pass in to create an https servercert
- Option to pass in to create an https serverpfx
- Can also be used to create an https server instead of key
& cert
liveCSS
- LiveReload option to enable live CSS reloading (defaults to true)liveImg
- LiveReload option to enable live images reloading (defaults to true)prefix
- Option to add prefix to all HTTP server routesdashboard
- A boolean to prevent tiny-lr from configuring a default
"home" route. Only used with the CLI (default: false)npm test
1var url = parse(this.request.url);
2var server = this.app;
3
4var ws = this.ws = new WebSocket('ws://' + url.host + '/livereload');
5
6ws.onopen = function(event) {
7 var hello = {
8 command: 'hello',
9 protocols: ['http://livereload.com/protocols/official-7']
10 };
11
12 ws.send(JSON.stringify(hello));
13};
14
15ws.onmessage = function(event) {
16 assert.deepEqual(event.data, JSON.stringify({
17 command: 'hello',
18 protocols: ['http://livereload.com/protocols/official-7'],
19 serverName: 'tiny-lr'
20 }));
21
22 assert.ok(Object.keys(server.clients).length);
23 done();
24};
properly cleans up established connection on exit.
# tiny-lr ## GET / respond with nothing, but respond.1var ws = this.ws; 2 3ws.onclose = done.bind(null, null); 4 5request(this.server) 6 .get('/kill') 7 .expect(200, function() { 8 console.log('server shutdown'); 9 });
1request(this.server) 2 .get('/') 3 .expect('Content-Type', /json/) 4 .expect('{"tinylr":"Welcome","version":"0.0.1"}') 5 .expect(200, done);
unknown route respond with proper 404 and error message.
## GET /changed with no clients, no files.1request(this.server) 2 .get('/whatev') 3 .expect('Content-Type', /json/) 4 .expect('{"error":"not_found","reason":"no such route"}') 5 .expect(404, done);
1request(this.server) 2 .get('/changed') 3 .expect('Content-Type', /json/) 4 .expect(/"clients":\[\]/) 5 .expect(/"files":\[\]/) 6 .expect(200, done);
with no clients, some files.
## POST /changed with no clients, no files.1request(this.server) 2 .get('/changed?files=gonna.css,test.css,it.css') 3 .expect('Content-Type', /json/) 4 .expect('{"clients":[],"files":["gonna.css","test.css","it.css"]}') 5 .expect(200, done);
1request(this.server) 2 .post('/changed') 3 .expect('Content-Type', /json/) 4 .expect(/"clients":\[\]/) 5 .expect(/"files":\[\]/) 6 .expect(200, done);
with no clients, some files.
## GET /livereload.js respond with livereload script.1var data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] }; 2 3request(this.server) 4 .post('/changed') 5 .send({ files: data.files }) 6 .expect('Content-Type', /json/) 7 .expect(JSON.stringify(data)) 8 .expect(200, done);
## GET /kill shutdown the server.1request(this.server) 2 .get('/livereload.js') 3 .expect(/LiveReload/) 4 .expect(200, done);
1var server = this.server; 2request(server) 3 .get('/kill') 4 .expect(200, function(err) { 5 if(err) return done(err); 6 assert.ok(!server._handle); 7 done(); 8 });
Tiny-lr is a LiveReload implementation. They really made frontend editing better for a lot of us. They have a LiveReload App on the Mac App Store you might want to check out.
To all contributors
@FGRibreau / pid.js gist) for the background friendly bin wrapper, used in make-livereload
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/13 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
78 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More