Neptunium, Promethium, Manganese
    Wondering what’s next for npm?Check out our public roadmap! »

    qrhook

    3.1.2 • Public • Published

    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

    Install

    npm i qrhook

    DownloadsWeekly Downloads

    1

    Version

    3.1.2

    License

    MIT

    Unpacked Size

    9.05 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar