\begin{quote}
Open stuff like URLs, files, executables. Cross-\/platform. \end{quote}
This is meant to be used in command-\/line tools and scripts, not in the browser.

If need this for Electron, use \href{https://electronjs.org/docs/api/shell\#shellopenitemfullpath}{\texttt{ {\ttfamily shell.\+open\+Item()}}} instead.

Note\+: The original \href{https://github.com/pwnall/node-open}{\texttt{ {\ttfamily open} package}} was previously deprecated in favor of this package, and we got the name, so this package is now named {\ttfamily open} instead of {\ttfamily opn}. If you\textquotesingle{}re upgrading from the original {\ttfamily open} package ({\ttfamily open@0.\+0.\+5} or lower), keep in mind that the API is different.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19092}{}\doxysubsubsection{Why?}\label{md_sfcode_node_modules_open_readme_autotoc_md19092}

\begin{DoxyItemize}
\item Actively maintained.
\item Supports app arguments.
\item Safer as it uses {\ttfamily spawn} instead of {\ttfamily exec}.
\item Fixes most of the open original {\ttfamily node-\/open} issues.
\item Includes the latest \href{https://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18}{\texttt{ {\ttfamily xdg-\/open} script}} for Linux.
\item Supports WSL paths to Windows apps under {\ttfamily /mnt/$\ast$}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19093}{}\doxysection{Install}\label{md_sfcode_node_modules_open_readme_autotoc_md19093}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install open }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19094}{}\doxysection{Usage}\label{md_sfcode_node_modules_open_readme_autotoc_md19094}

\begin{DoxyCode}{0}
\DoxyCodeLine{const open = require('open');}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    // Opens the image in the default image viewer and waits for the opened app to quit.}
\DoxyCodeLine{    await open('unicorn.png', \{wait: true\});}
\DoxyCodeLine{    console.log('The image viewer app quit');}
\DoxyCodeLine{}
\DoxyCodeLine{    // Opens the URL in the default browser.}
\DoxyCodeLine{    await open('https://sindresorhus.com');}
\DoxyCodeLine{}
\DoxyCodeLine{    // Opens the URL in a specified browser.}
\DoxyCodeLine{    await open('https://sindresorhus.com', \{app: 'firefox'\});}
\DoxyCodeLine{}
\DoxyCodeLine{    // Specify app arguments.}
\DoxyCodeLine{    await open('https://sindresorhus.com', \{app: ['google chrome', '-\/-\/incognito']\});}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19095}{}\doxysection{API}\label{md_sfcode_node_modules_open_readme_autotoc_md19095}
It uses the command {\ttfamily open} on mac\+OS, {\ttfamily start} on Windows and {\ttfamily xdg-\/open} on other platforms.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19096}{}\doxysubsection{open(target, options?)}\label{md_sfcode_node_modules_open_readme_autotoc_md19096}
Returns a promise for the \href{https://nodejs.org/api/child_process.html\#child_process_class_childprocess}{\texttt{ spawned child process}}. You would normally not need to use this for anything, but it can be useful if you\textquotesingle{}d like to attach custom event listeners or perform other operations directly on the spawned process.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19097}{}\doxysubsubsection{target}\label{md_sfcode_node_modules_open_readme_autotoc_md19097}
Type\+: {\ttfamily string}

The thing you want to open. Can be a URL, file, or executable.

Opens in the default app for the file type. For example, URLs opens in your default browser.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19098}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_open_readme_autotoc_md19098}
Type\+: {\ttfamily object}\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19099}{}\doxyparagraph{wait}\label{md_sfcode_node_modules_open_readme_autotoc_md19099}
Type\+: {\ttfamily boolean}\textbackslash{} Default\+: {\ttfamily false}

Wait for the opened app to exit before fulfilling the promise. If {\ttfamily false} it\textquotesingle{}s fulfilled immediately when opening the app.

Note that it waits for the app to exit, not just for the window to close.

On Windows, you have to explicitly specify an app for it to be able to wait.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19100}{}\doxyparagraph{background $<$sup$>$(mac\+OS only)$<$/sup$>$}\label{md_sfcode_node_modules_open_readme_autotoc_md19100}
Type\+: {\ttfamily boolean}\textbackslash{} Default\+: {\ttfamily false}

Do not bring the app to the foreground.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19101}{}\doxyparagraph{app}\label{md_sfcode_node_modules_open_readme_autotoc_md19101}
Type\+: {\ttfamily string $\vert$ string\mbox{[}\mbox{]}}

Specify the app to open the {\ttfamily target} with, or an array with the app and app arguments.

The app name is platform dependent. Don\textquotesingle{}t hard code it in reusable modules. For example, Chrome is {\ttfamily google chrome} on mac\+OS, {\ttfamily google-\/chrome} on Linux and {\ttfamily chrome} on Windows.

You may also pass in the app\textquotesingle{}s full path. For example on WSL, this can be {\ttfamily /mnt/c/\+Program Files (x86)/\+Google/\+Chrome/\+Application/chrome.exe} for the Windows installation of Chrome.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19102}{}\doxyparagraph{url}\label{md_sfcode_node_modules_open_readme_autotoc_md19102}
Type\+: {\ttfamily boolean}\textbackslash{} Default\+: {\ttfamily false}

Uses {\ttfamily URL} to encode the target before executing it.~\newline
 We do not recommend using it on targets that are not URLs.

Especially useful when dealing with the \href{\#double-quotes-on-windows}{\texttt{ double-\/quotes on Windows}} caveat.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19103}{}\doxyparagraph{allow\+Nonzero\+Exit\+Code}\label{md_sfcode_node_modules_open_readme_autotoc_md19103}
Type\+: {\ttfamily boolean}\textbackslash{} Default\+: {\ttfamily false}

Allow the opened app to exit with nonzero exit code when the {\ttfamily wait} option is {\ttfamily true}.

We do not recommend setting this option. The convention for success is exit code zero.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19104}{}\doxysection{Caveats}\label{md_sfcode_node_modules_open_readme_autotoc_md19104}
\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19105}{}\doxysubsection{Double-\/quotes on Windows}\label{md_sfcode_node_modules_open_readme_autotoc_md19105}
TL;DR\+: All double-\/quotes are stripped from the {\ttfamily target} and do not get to your desired destination (on Windows!).

Due to specific behaviors of Window\textquotesingle{}s Command Prompt ({\ttfamily cmd.\+exe}) regarding ampersand ({\ttfamily \&}) characters breaking commands and URLs, double-\/quotes are now a special case.

The solution (\href{https://github.com/sindresorhus/open/pull/146}{\texttt{ \#146}}) to this and other problems was to leverage the fact that {\ttfamily cmd.\+exe} interprets a double-\/quoted argument as a plain text argument just by quoting it (like Node.\+js already does). Unfortunately, {\ttfamily cmd.\+exe} can only do {\bfseries{one}} of two things\+: handle them all {\bfseries{OR}} not handle them at all. As per its own documentation\+:

$>${\itshape If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote ("{}) characters\+:} \begin{quote}

\begin{DoxyEnumerate}
\item {\itshape If all of the following conditions are met, then quote characters on the command line are preserved\+:}
\begin{DoxyItemize}
\item {\itshape no /S switch}
\item {\itshape exactly two quote characters}
\item {\itshape no special characters between the two quote characters, where special is one of\+: \&$<$$>$()@$^\wedge$$\vert$}
\item {\itshape there are one or more whitespace characters between the two quote characters}
\item {\itshape the string between the two quote characters is the name of an executable file.}
\end{DoxyItemize}
\item {\itshape Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character.} 
\end{DoxyEnumerate}\end{quote}
The option that solved all of the problems was the second one, and for additional behavior consistency we\textquotesingle{}re also now using the {\ttfamily /S} switch, so we {\bfseries{always}} get the second option. The caveat is that this built-\/in double-\/quotes handling ends up stripping all of them from the command line and so far we weren\textquotesingle{}t able to find an escaping method that works (if you do, please feel free to contribute!).

To make this caveat somewhat less impactful (at least for URLs), check out the \href{\#url}{\texttt{ url option}}. Double-\/quotes will be \char`\"{}preserved\char`\"{} when using it with an URL.\hypertarget{md_sfcode_node_modules_open_readme_autotoc_md19106}{}\doxysection{Related}\label{md_sfcode_node_modules_open_readme_autotoc_md19106}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/open-cli}{\texttt{ open-\/cli}} -\/ CLI for this module
\item \href{https://github.com/sindresorhus/open-editor}{\texttt{ open-\/editor}} -\/ Open files in your editor at a specific line and column
\end{DoxyItemize}

\DoxyHorRuler{0}


 {\bfseries{ \href{https://tidelift.com/subscription/pkg/npm-opn?utm_source=npm-opn&utm_medium=referral&utm_campaign=readme}{\texttt{ Get professional support for this package with a Tidelift subscription}} }} ~\newline
 \textsubscript{ Tidelift helps make open source sustainable for maintainers while giving companies~\newline
assurances about security, maintenance, and licensing for their dependencies. }  