1.0.0 • Published 7 years ago

open-it v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

OpenIt

An intelligent cross-platform opening utility built on top of opn.

Why?

OpenIt provides some extra functionality on top of opn that enables it to wait for hosts to be available before launching the browser. This is great for instances where the host may not be available immediately, such as when a Docker container is warming up.

Requirements

node >= 7.6.0

Install

$ npm install --save open-it

- OR -

$ yarn add open-it

Usage

const openIt = require('open-it');

// Opens the URL in the default browser
openIt('https://www.google.com');

// Specify the app to open it in
openIt('https://www.google.com', { app: 'google chrome' });

// Specify app arguments
openIt('https://www.google.com', { app: ['google chrome', '--incognito'] });

// Never opens the browser because the resource doesn't exist or is unavailable
openIt('http://a-non-existant-website.com');

API

OpenIt(target, options)

Returns a promise containing the spawned child process created by opn.

target

Type: String

The resource you want to open. Can be a URL, file, or executable.

Opens in the default app for the file type. For example, URLs open in your default browser.

options

Type: Object

delay

Type: Number Default: 500

The amount of time to wait (in milliseconds) between each retry in accesing the resource.

maxRetries

Type: Number Default: 10

The maximum retry attempts that will be made to connect to the resource.

wait

Type: Boolean Default: false

Wait for the opened app to exit before fulfilling the promise. Turned off by default.

On Windows you have to explicitly specify the app for it to be able to wait.

app

Type: String || Array

Specify the app to open the target with, or an array with the app and app arguments.

The app name is platform dependant. Don't hard code it in reusable modules. For examples, chrome is google chrome on macOS, google-chrome on Linux, and chrome on Windows.

More Info

For more information on opn, please visit its github repository.

License

MIT © Matthew Switzer

1.0.1

7 years ago

1.0.0

7 years ago