source: trip-planner-front/node_modules/opn/readme.md@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1# opn
2
3> A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform.
4
5If need this for Electron, use [`shell.openItem()`](https://electronjs.org/docs/api/shell#shellopenitemfullpath) instead.
6
7
8#### Why?
9
10- Actively maintained
11- Supports app arguments
12- Safer as it uses `spawn` instead of `exec`
13- Fixes most of the open `node-open` issues
14- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux
15
16
17## Install
18
19```
20$ npm install opn
21```
22
23
24## Usage
25
26```js
27const opn = require('opn');
28
29// Opens the image in the default image viewer
30opn('unicorn.png').then(() => {
31 // image viewer closed
32});
33
34// Opens the url in the default browser
35opn('http://sindresorhus.com');
36
37// Specify the app to open in
38opn('http://sindresorhus.com', {app: 'firefox'});
39
40// Specify app arguments
41opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
42```
43
44
45## API
46
47Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
48
49### opn(target, [options])
50
51Returns a promise for the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
52
53#### target
54
55Type: `string`
56
57The thing you want to open. Can be a URL, file, or executable.
58
59Opens in the default app for the file type. For example, URLs opens in your default browser.
60
61#### options
62
63Type: `Object`
64
65##### wait
66
67Type: `boolean`<br>
68Default: `true`
69
70Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
71
72On Windows you have to explicitly specify an app for it to be able to wait.
73
74##### app
75
76Type: `string` `Array`
77
78Specify the app to open the `target` with, or an array with the app and app arguments.
79
80The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows.
81
82
83## Related
84
85- [opn-cli](https://github.com/sindresorhus/opn-cli) - CLI for this module
86
87
88## License
89
90MIT © [Sindre Sorhus](https://sindresorhus.com)
Note: See TracBrowser for help on using the repository browser.