opnr
Sniffs process.stdin
for ndjson and launches the browser when a message with url
and type: 'connect'
is consumed.
It looks for JSON objects with the following format:
type: 'connect' url: 'some-page.com'
URLs are parsed as addresses, so the above opens the default browser to http://some-page.com/
. You can configure the action to listen for with the --type
field.
This can be used alongside ndjson-emitting CLI tools, like budo:
# launch the browser once an available port is found budo index.js | opnr
Usage
Usage: opnr [opts] Opts: --type the "type" to launch on, defualt "connect"
Example
A common scenario might be an async action triggered by a CLI tool that involves a browser launch.
server.js
var http = //get next available port { if err throw err //start your server var server = http server}
Install opnr
, and optionally garnish
for prettier logs.
npm install opnr garnish -g
Now you can pipe things together to run your server and open the browser when ready.
node server.js | opnr | garnish
License
MIT, see LICENSE.md for details.