Package Exports
- opn
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (opn) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
opn
A better node-open. Opens stuff like websites, files, executables. Cross-platform.
Why?
- Actively maintained
- Supports app arguments
- Safer as it uses
spawninstead ofexec - Fixes most of the open
node-openissues - Comes with a CLI for use in your scripts
- Includes the latest
xdg-openscript for Linux
Install
$ npm install --save opnUsage
var opn = require('opn');
opn('unicorn.png');
// opens the image in the default image viewer
opn('http://sindresorhus.com');
// opens the url in the default browser
opn('http://sindresorhus.com', 'firefox');
// specify the app to open in
opn('http://sindresorhus.com', ['google chrome', '--incognito']);
// specify app argumentsAPI
Uses the command open on OS X, start on Windows and xdg-open on other platforms.
opn(target, [app], [callback])
target
Required
Type: string
The thing you want to open. Can be a URL, file, or executable.
Opens in the default app for the file type. Eg. URLs opens in your default browser.
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 dependent. Don't hard code it in reusable modules. Eg. Chrome is google chrome on OS X, google-chrome on Linux and chrome on Windows.
callback(error)
Type: function
Called when the opened app exits.
On Windows you have to explicitly specify an app for it to be able to wait.
CLI
$ npm install --global opn$ opn --help
Usage
$ opn <file|url> [app] [app arguments]
Example
$ opn http://sindresorhus.com
$ opn http://sindresorhus.com firefox
$ opn http://sindresorhus.com 'google chrome' --incognito
$ opn unicorn.pngLicense
MIT © Sindre Sorhus