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