UNPKG

1.99 kBMarkdownView Raw
1# opn
2
3> A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform.
4
5
6#### Why?
7
8- Actively maintained
9- Supports app arguments
10- Safer as it uses `spawn` instead of `exec`
11- Fixes most of the open `node-open` issues
12- Comes with a CLI for use in your scripts
13- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux
14
15
16## Install
17
18```
19$ npm install --save opn
20```
21
22
23## Usage
24
25```js
26var opn = require('opn');
27
28opn('unicorn.png');
29// opens the image in the default image viewer
30
31opn('http://sindresorhus.com');
32// opens the url in the default browser
33
34opn('http://sindresorhus.com', 'firefox');
35// specify the app to open in
36
37opn('http://sindresorhus.com', ['google chrome', '--incognito']);
38// specify app arguments
39```
40
41
42## API
43
44Uses the command `open` on OS X, `start` on Windows and `xdg-open` on other platforms.
45
46### opn(target, [app], [callback])
47
48#### target
49
50*Required*
51Type: `string`
52
53The thing you want to open. Can be a URL, file, or executable.
54
55Opens in the default app for the file type. Eg. URLs opens in your default browser.
56
57#### app
58
59Type: `string`, `array`
60
61Specify the app to open the `target` with, or an array with the app and app arguments.
62
63The 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.
64
65#### callback(error)
66
67Type: `function`
68
69Called when the opened app exits.
70
71On Windows you have to explicitly specify an app for it to be able to wait.
72
73
74## CLI
75
76```
77$ npm install --global opn
78```
79
80```
81$ opn --help
82
83 Usage
84 $ opn <file|url> [app] [app arguments]
85
86 Example
87 $ opn http://sindresorhus.com
88 $ opn http://sindresorhus.com firefox
89 $ opn http://sindresorhus.com 'google chrome' --incognito
90 $ opn unicorn.png
91```
92
93
94## License
95
96MIT © [Sindre Sorhus](http://sindresorhus.com)