A simple temporary file and directory creator for \href{http://nodejs.org/}{\texttt{ node.\+js.}}

\href{https://travis-ci.org/raszi/node-tmp}{\texttt{ }} \href{https://david-dm.org/raszi/node-tmp}{\texttt{ }} \href{https://badge.fury.io/js/tmp}{\texttt{ }} \href{https://raszi.github.io/node-tmp/}{\texttt{ }} \href{https://snyk.io/test/npm/tmp}{\texttt{ }}\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15318}{}\doxysection{About}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15318}
This is a \href{https://www.npmjs.com/browse/depended/tmp}{\texttt{ widely used library}} to create temporary files and directories in a \href{http://nodejs.org/}{\texttt{ node.\+js}} environment.

Tmp offers both an asynchronous and a synchronous API. For all API calls, all the parameters are optional. There also exists a promisified version of the API, see \href{https://github.com/benjamingr/tmp-promise}{\texttt{ tmp-\/promise}}.

Tmp uses crypto for determining random file names, or, when using templates, a six letter random identifier. And just in case that you do not have that much entropy left on your system, Tmp will fall back to pseudo random numbers.

You can set whether you want to remove the temporary file on process exit or not.

If you do not want to store your temporary directories and files in the standard OS temporary directory, then you are free to override that as well.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15319}{}\doxysection{An Important Note on Compatibility}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15319}
See the \mbox{\hyperlink{md_sfcode_node_modules_karma_node_modules_tmp_CHANGELOG}{CHANGELOG}} for more information.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15320}{}\doxysubsection{Version 0.\+1.\+0}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15320}
Since version 0.\+1.\+0, all support for node versions $<$ 0.\+10.\+0 has been dropped.

Most importantly, any support for earlier versions of node-\/tmp was also dropped.

If you still require node versions $<$ 0.\+10.\+0, then you must limit your node-\/tmp dependency to versions below 0.\+1.\+0.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15321}{}\doxysubsection{Version 0.\+0.\+33}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15321}
Since version 0.\+0.\+33, all support for node versions $<$ 0.\+8 has been dropped.

If you still require node version 0.\+8, then you must limit your node-\/tmp dependency to version 0.\+0.\+33.

For node versions $<$ 0.\+8 you must limit your node-\/tmp dependency to versions $<$ 0.\+0.\+33.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15322}{}\doxysection{How to install}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15322}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install tmp }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15323}{}\doxysection{Usage}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15323}
Please also check \href{https://raszi.github.io/node-tmp/}{\texttt{ API docs}}.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15324}{}\doxysubsection{Asynchronous file creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15324}
Simple temporary file creation, the file will be closed and unlinked on process exit.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.file(function \_tempFileCreated(err, path, fd, cleanupCallback) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('File: ', path);}
\DoxyCodeLine{  console.log('Filedescriptor: ', fd);}
\DoxyCodeLine{  }
\DoxyCodeLine{  // If we don't need the file anymore we could manually call the cleanupCallback}
\DoxyCodeLine{  // But that is not necessary if we didn't pass the keep option because the library}
\DoxyCodeLine{  // will clean after itself.}
\DoxyCodeLine{  cleanupCallback();}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15325}{}\doxysubsection{Synchronous file creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15325}
A synchronous version of the above.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const tmpobj = tmp.fileSync();}
\DoxyCodeLine{console.log('File: ', tmpobj.name);}
\DoxyCodeLine{console.log('Filedescriptor: ', tmpobj.fd);}
\DoxyCodeLine{  }
\DoxyCodeLine{// If we don't need the file anymore we could manually call the removeCallback}
\DoxyCodeLine{// But that is not necessary if we didn't pass the keep option because the library}
\DoxyCodeLine{// will clean after itself.}
\DoxyCodeLine{tmpobj.removeCallback(); }

\end{DoxyCode}


Note that this might throw an exception if either the maximum limit of retries for creating a temporary name fails, or, in case that you do not have the permission to write to the directory where the temporary file should be created in.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15326}{}\doxysubsection{Asynchronous directory creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15326}
Simple temporary directory creation, it will be removed on process exit.

If the directory still contains items on process exit, then it won\textquotesingle{}t be removed.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.dir(function \_tempDirCreated(err, path, cleanupCallback) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('Dir: ', path);}
\DoxyCodeLine{  }
\DoxyCodeLine{  // Manual cleanup}
\DoxyCodeLine{  cleanupCallback();}
\DoxyCodeLine{\}); }

\end{DoxyCode}


If you want to cleanup the directory even when there are entries in it, then you can pass the {\ttfamily unsafe\+Cleanup} option when creating it.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15327}{}\doxysubsection{Synchronous directory creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15327}
A synchronous version of the above.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const tmpobj = tmp.dirSync();}
\DoxyCodeLine{console.log('Dir: ', tmpobj.name);}
\DoxyCodeLine{// Manual cleanup}
\DoxyCodeLine{tmpobj.removeCallback(); }

\end{DoxyCode}


Note that this might throw an exception if either the maximum limit of retries for creating a temporary name fails, or, in case that you do not have the permission to write to the directory where the temporary directory should be created in.\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15328}{}\doxysubsection{Asynchronous filename generation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15328}
It is possible with this library to generate a unique filename in the specified directory.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.tmpName(function \_tempNameGenerated(err, path) \{}
\DoxyCodeLine{    if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log('Created temporary filename: ', path);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15329}{}\doxysubsection{Synchronous filename generation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15329}
A synchronous version of the above.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const name = tmp.tmpNameSync();}
\DoxyCodeLine{console.log('Created temporary filename: ', name); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15330}{}\doxysection{Advanced usage}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15330}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15331}{}\doxysubsection{Asynchronous file creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15331}
Creates a file with mode {\ttfamily 0644}, prefix will be {\ttfamily prefix-\/} and postfix will be {\ttfamily .txt}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.file(\{ mode: 0o644, prefix: 'prefix-\/', postfix: '.txt' \}, function \_tempFileCreated(err, path, fd) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('File: ', path);}
\DoxyCodeLine{  console.log('Filedescriptor: ', fd);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15332}{}\doxysubsection{Synchronous file creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15332}
A synchronous version of the above.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const tmpobj = tmp.fileSync(\{ mode: 0o644, prefix: 'prefix-\/', postfix: '.txt' \});}
\DoxyCodeLine{console.log('File: ', tmpobj.name);}
\DoxyCodeLine{console.log('Filedescriptor: ', tmpobj.fd); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15333}{}\doxysubsection{Controlling the Descriptor}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15333}
As a side effect of creating a unique file {\ttfamily tmp} gets a file descriptor that is returned to the user as the {\ttfamily fd} parameter. The descriptor may be used by the application and is closed when the {\ttfamily remove\+Callback} is invoked.

In some use cases the application does not need the descriptor, needs to close it without removing the file, or needs to remove the file without closing the descriptor. Two options control how the descriptor is managed\+:


\begin{DoxyItemize}
\item {\ttfamily discard\+Descriptor} -\/ if {\ttfamily true} causes {\ttfamily tmp} to close the descriptor after the file is created. In this case the {\ttfamily fd} parameter is undefined.
\item {\ttfamily detach\+Descriptor} -\/ if {\ttfamily true} causes {\ttfamily tmp} to return the descriptor in the {\ttfamily fd} parameter, but it is the application\textquotesingle{}s responsibility to close it when it is no longer needed.
\end{DoxyItemize}


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.file(\{ discardDescriptor: true \}, function \_tempFileCreated(err, path, fd, cleanupCallback) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{  // fd will be undefined, allowing application to use fs.createReadStream(path)}
\DoxyCodeLine{  // without holding an unused descriptor open.}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.file(\{ detachDescriptor: true \}, function \_tempFileCreated(err, path, fd, cleanupCallback) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{  cleanupCallback();}
\DoxyCodeLine{  // Application can store data through fd here; the space used will automatically}
\DoxyCodeLine{  // be reclaimed by the operating system when the descriptor is closed or program}
\DoxyCodeLine{  // terminates.}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15334}{}\doxysubsection{Asynchronous directory creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15334}
Creates a directory with mode {\ttfamily 0755}, prefix will be {\ttfamily my\+Tmp\+Dir\+\_\+}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.dir(\{ mode: 0o750, prefix: 'myTmpDir\_' \}, function \_tempDirCreated(err, path) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('Dir: ', path);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15335}{}\doxysubsection{Synchronous directory creation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15335}
Again, a synchronous version of the above.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const tmpobj = tmp.dirSync(\{ mode: 0750, prefix: 'myTmpDir\_' \});}
\DoxyCodeLine{console.log('Dir: ', tmpobj.name); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15336}{}\doxysubsection{mkstemp like, asynchronously}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15336}
Creates a new temporary directory with mode {\ttfamily 0700} and filename like {\ttfamily /tmp/tmp-\/nk2\+J1u}.

IMPORTANT NOTE\+: template no longer accepts a path. Use the dir option instead if you require tmp to create your temporary filesystem object in a different place than the default {\ttfamily tmp.\+tmpdir}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.dir(\{ template: 'tmp-\/XXXXXX' \}, function \_tempDirCreated(err, path) \{}
\DoxyCodeLine{  if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('Dir: ', path);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15337}{}\doxysubsection{mkstemp like, synchronously}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15337}
This will behave similarly to the asynchronous version.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const tmpobj = tmp.dirSync(\{ template: 'tmp-\/XXXXXX' \});}
\DoxyCodeLine{console.log('Dir: ', tmpobj.name); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15338}{}\doxysubsection{Asynchronous filename generation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15338}
Using {\ttfamily tmp\+Name()} you can create temporary file names asynchronously. The function accepts all standard options, e.\+g. {\ttfamily prefix}, {\ttfamily postfix}, {\ttfamily dir}, and so on.

You can also leave out the options altogether and just call the function with a callback as first parameter.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{const options = \{\};}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.tmpName(options, function \_tempNameGenerated(err, path) \{}
\DoxyCodeLine{    if (err) throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log('Created temporary filename: ', path);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15339}{}\doxysubsection{Synchronous filename generation}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15339}
The {\ttfamily tmp\+Name\+Sync()} function works similarly to {\ttfamily tmp\+Name()}. Again, you can leave out the options altogether and just invoke the function without any parameters.


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{const options = \{\};}
\DoxyCodeLine{const tmpname = tmp.tmpNameSync(options);}
\DoxyCodeLine{console.log('Created temporary filename: ', tmpname); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15340}{}\doxysection{Graceful cleanup}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15340}
If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary object removal.

To enforce this, you can call the {\ttfamily set\+Graceful\+Cleanup()} method\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const tmp = require('tmp');}
\DoxyCodeLine{}
\DoxyCodeLine{tmp.setGracefulCleanup(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15341}{}\doxysection{Options}\label{md_sfcode_node_modules_karma_node_modules_tmp_README_autotoc_md15341}
All options are optional \+:)


\begin{DoxyItemize}
\item {\ttfamily name}\+: a fixed name that overrides random name generation, the name must be relative and must not contain path segments
\item {\ttfamily mode}\+: the file mode to create with, falls back to {\ttfamily 0o600} on file creation and {\ttfamily 0o700} on directory creation
\item {\ttfamily prefix}\+: the optional prefix, defaults to {\ttfamily tmp}
\item {\ttfamily postfix}\+: the optional postfix
\item {\ttfamily template}\+: \href{http://www.kernel.org/doc/man-pages/online/pages/man3/mkstemp.3.html}{\texttt{ {\ttfamily mkstemp}}} like filename template, no default, can be either an absolute or a relative path that resolves to a relative path of the system\textquotesingle{}s default temporary directory, must include {\ttfamily XXXXXX} once for random name generation, e.\+g. \textquotesingle{}foo/bar/\+XXXXXX\textquotesingle{}. Absolute paths are also fine as long as they are relative to os.\+tmpdir(). Any directories along the so specified path must exist, otherwise a ENOENT error will be thrown upon access, as tmp will not check the availability of the path, nor will it establish the requested path for you.
\item {\ttfamily dir}\+: the optional temporary directory that must be relative to the system\textquotesingle{}s default temporary directory. absolute paths are fine as long as they point to a location under the system\textquotesingle{}s default temporary directory. Any directories along the so specified path must exist, otherwise a ENOENT error will be thrown upon access, as tmp will not check the availability of the path, nor will it establish the requested path for you.
\item {\ttfamily tmpdir}\+: allows you to override the system\textquotesingle{}s root tmp directory
\item {\ttfamily tries}\+: how many times should the function try to get a unique filename before giving up, default {\ttfamily 3}
\item {\ttfamily keep}\+: signals that the temporary file or directory should not be deleted on exit, default is {\ttfamily false}
\begin{DoxyItemize}
\item In order to clean up, you will have to call the provided {\ttfamily cleanup\+Callback} function manually.
\end{DoxyItemize}
\item {\ttfamily unsafe\+Cleanup}\+: recursively removes the created temporary directory, even when it\textquotesingle{}s not empty. default is {\ttfamily false}
\item {\ttfamily detach\+Descriptor}\+: detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection
\item {\ttfamily discard\+Descriptor}\+: discards the file descriptor (closes file, fd is -\/1), tmp will no longer try closing the file during garbage collection 
\end{DoxyItemize}