source: trip-planner-front/node_modules/open/readme.md@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 4.8 KB
Line 
1# open
2
3> Open stuff like URLs, files, executables. Cross-platform.
4
5This is meant to be used in command-line tools and scripts, not in the browser.
6
7If you need this for Electron, use [`shell.openPath()`](https://www.electronjs.org/docs/api/shell#shellopenpathpath) instead.
8
9Note: The original [`open` package](https://github.com/pwnall/node-open) was previously deprecated in favor of this package, and we got the name, so this package is now named `open` instead of `opn`. If you're upgrading from the original `open` package (`open@0.0.5` or lower), keep in mind that the API is different.
10
11#### Why?
12
13- Actively maintained.
14- Supports app arguments.
15- Safer as it uses `spawn` instead of `exec`.
16- Fixes most of the original `node-open` issues.
17- Includes the latest [`xdg-open` script](https://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux.
18- Supports WSL paths to Windows apps.
19
20## Install
21
22```
23$ npm install open
24```
25
26## Usage
27
28```js
29const open = require('open');
30
31// Opens the image in the default image viewer and waits for the opened app to quit.
32await open('unicorn.png', {wait: true});
33console.log('The image viewer app quit');
34
35// Opens the URL in the default browser.
36await open('https://sindresorhus.com');
37
38// Opens the URL in a specified browser.
39await open('https://sindresorhus.com', {app: {name: 'firefox'}});
40
41// Specify app arguments.
42await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
43```
44
45## API
46
47It uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
48
49### open(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`\
68Default: `false`
69
70Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
71
72Note that it waits for the app to exit, not just for the window to close.
73
74On Windows, you have to explicitly specify an app for it to be able to wait.
75
76##### background <sup>(macOS only)</sup>
77
78Type: `boolean`\
79Default: `false`
80
81Do not bring the app to the foreground.
82
83##### newInstance <sup>(macOS only)</sup>
84
85Type: `boolean`\
86Default: `false`
87
88Open a new instance of the app even it's already running.
89
90A new instance is always opened on other platforms.
91
92##### app
93
94Type: `{name: string | string[], arguments?: string[]} | Array<{name: string | string[], arguments: string[]}>`
95
96Specify the `name` of the app to open the `target` with and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
97
98The 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. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use.
99
100You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.
101
102##### allowNonzeroExitCode
103
104Type: `boolean`\
105Default: `false`
106
107Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
108
109We do not recommend setting this option. The convention for success is exit code zero.
110
111### open.apps
112
113An object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app).
114
115```js
116const open = require('open');
117
118await open('https://google.com', {
119 app: {
120 name: open.apps.chrome
121 }
122});
123```
124
125#### Supported apps
126
127- [`chrome`](https://www.google.com/chrome) - Web browser
128- [`firefox`](https://www.mozilla.org/firefox) - Web browser
129- [`edge`](https://www.microsoft.com/edge) - Web browser
130
131## Related
132
133- [open-cli](https://github.com/sindresorhus/open-cli) - CLI for this module
134- [open-editor](https://github.com/sindresorhus/open-editor) - Open files in your editor at a specific line and column
135
136---
137
138<div align="center">
139 <b>
140 <a href="https://tidelift.com/subscription/pkg/npm-opn?utm_source=npm-opn&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
141 </b>
142 <br>
143 <sub>
144 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
145 </sub>
146</div>
Note: See TracBrowser for help on using the repository browser.