3.1.2 • Published 5 years ago

qrhook v3.1.2

Weekly downloads
18
License
MIT
Repository
github
Last release
5 years ago

QRHook

QRHook is a small utility for creating QR-codes that will call a given function when scanned.

Installation

The module can easily be retrieved from the npm registry by running

npm install --save qrhook

Example usage

const QRHook = require("qrhook");

const html = "<h1>Hello there!</h1>";
//Generate and log a data url using the onScan-method as a hook
QRHook(onScan, {})
 .then(e => console.log(e.code))
 .catch(console.error);

//Handle incoming requests (created by scans)
function onScan(req, res) {
    console.log("Somebody scanned *OUR* code! ( ͡☭ ͜ʖ ͡☭)");
    //The content type is automatically set to text/html, so there's no need to worry about that
    res.end(html);
}

/*
When the QR-code is then scanned, the scanning browser will display the heading "Hello there!", and the server will call the onScan()-method
*/

API

QRHook(hook, opts)

  • returns: <Promise<Object {code, destroy}>> Promise that resolves to an object with a data url and a destroy function, which immediately invalidates the code
    • hook <Function (req, res)> The function to be called when the code is scanned. Will be called with the request and response objects provided by the HTTP server, and is thus in charge of writing to - and ending the response
    • opts <Object> An object containing various options
      • maxUses <Number> The maximum amount of uses before the code becomes invalid. Defaults to Infinity
      • expires <Date> The UTC timestamp up to which the code will be valid. Defaults to Infinity
      • uniqueOnly <Boolean> If set to true, then a browser can only trigger the hook once. Defaults to false
      • addressType <String> Dictates what address the QR-code should point to. Can be internal, external or ngrok. Defaults to ngrok
      • ngrokOpts <Object> The options to pass to ngrok (only applies if addressType is set to ngrok)
      • port <Number> Forces the server to listen on a specific port
3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago