\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20508}{}\doxysection{Installation}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20508}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ [sudo] npm install portfinder }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20509}{}\doxysection{Usage}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20509}
The {\ttfamily portfinder} module has a simple interface\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var portfinder = require('portfinder');}
\DoxyCodeLine{}
\DoxyCodeLine{portfinder.getPort(function (err, port) \{}
\DoxyCodeLine{  //}
\DoxyCodeLine{  // `port` is guaranteed to be a free port}
\DoxyCodeLine{  // in this scope.}
\DoxyCodeLine{  //}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Or with promise (if Promise are supported) \+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const portfinder = require('portfinder');}
\DoxyCodeLine{}
\DoxyCodeLine{portfinder.getPortPromise()}
\DoxyCodeLine{  .then((port) => \{}
\DoxyCodeLine{      //}
\DoxyCodeLine{      // `port` is guaranteed to be a free port}
\DoxyCodeLine{      // in this scope.}
\DoxyCodeLine{      //}
\DoxyCodeLine{  \})}
\DoxyCodeLine{  .catch((err) => \{}
\DoxyCodeLine{      //}
\DoxyCodeLine{      // Could not get a free port, `err` contains the reason.}
\DoxyCodeLine{      //}
\DoxyCodeLine{  \}); }

\end{DoxyCode}


If {\ttfamily portfinder.\+get\+Port\+Promise()} is called on a Node version without Promise ($<$4), it will throw an Error unless \href{http://bluebirdjs.com/docs/getting-started.html}{\texttt{ Bluebird}} or any Promise pollyfill is used.\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20510}{}\doxysubsection{Ports search scope}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20510}
By default {\ttfamily portfinder} will start searching from {\ttfamily 8000} and scan until maximum port number ({\ttfamily 65535}) is reached.

You can change this globally by setting\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{portfinder.basePort = 3000;    // default: 8000}
\DoxyCodeLine{portfinder.highestPort = 3333; // default: 65535 }

\end{DoxyCode}


or by passing optional options object on each invocation\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{portfinder.getPort(\{}
\DoxyCodeLine{    port: 3000,    // minimum port}
\DoxyCodeLine{    stopPort: 3333 // maximum port}
\DoxyCodeLine{\}, callback); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20511}{}\doxysection{Run Tests}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20511}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20512}{}\doxysubsubsection{Author\+: $<$a href=\char`\"{}http\+://nodejitsu.\+com\char`\"{}$>$\+Charlie Robbins$<$/a$>$}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20512}
\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20513}{}\doxysubsubsection{Maintainer\+: $<$a href=\char`\"{}https\+://github.\+com/eriktrom\char`\"{}$>$\+Erik Trom$<$/a$>$}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20513}
\hypertarget{md_sfcode_node_modules_portfinder_README_autotoc_md20514}{}\doxysubsubsection{License\+: MIT/\+X11}\label{md_sfcode_node_modules_portfinder_README_autotoc_md20514}
