UNPKG

1.58 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- Includes the latest [xdg-open script](http://portland.freedesktop.org/download/)
10- Fixes most of the `node-open` issues
11
12
13## Install
14
15```bash
16$ npm install --save opn
17```
18
19
20## Usage
21
22```js
23var opn = require('opn');
24
25opn('http://sindresorhus.com');
26// opens that url in the default browser
27
28opn('http://sindresorhus.com', 'firefox');
29// you can also specify the app to open in
30
31opn('unicorn.png');
32// opens the image in the default image viewer
33```
34
35
36## API
37
38Uses the command `open` on OS X, `start` on Windows and `xdg-open` on other platforms.
39
40### opn(target, [app, callback])
41
42#### target
43
44*Required*
45Type: `string`
46
47The thing you want to open. Can be a url, file, or executable.
48
49Opens in the default app for the file type. Eg. urls opens in your default browser.
50
51#### app
52
53Type: `string`
54
55Specify the app to open the `target` with.
56
57The app name is platform dependent. Don't hard code it in reusable modules.
58
59#### callback(err)
60
61Type: `function`
62
63Executes when the opened app exits.
64
65On Windows you have to explicitly specify an app for it to be able to wait.
66
67
68## CLI
69
70You can also use it as a CLI app by installing it globally:
71
72```bash
73$ npm install --global opn
74```
75
76#### Usage
77
78```bash
79$ opn --help
80
81Usage
82 $ opn <file|url> [app]
83
84Example
85 $ opn http://sindresorhus.com
86 $ opn http://sindresorhus.com firefox
87 $ opn unicorn.png
88```
89
90
91## License
92
93MIT © [Sindre Sorhus](http://sindresorhus.com)