{\ttfamily fs-\/extra} adds file system methods that aren\textquotesingle{}t included in the native {\ttfamily fs} module and adds promise support to the {\ttfamily fs} methods. It also uses \href{https://github.com/isaacs/node-graceful-fs}{\texttt{ {\ttfamily graceful-\/fs}}} to prevent {\ttfamily EMFILE} errors. It should be a drop in replacement for {\ttfamily fs}.

\href{https://www.npmjs.org/package/fs-extra}{\texttt{ }} \href{https://github.com/jprichardson/node-fs-extra/blob/master/LICENSE}{\texttt{ }} \href{http://travis-ci.org/jprichardson/node-fs-extra}{\texttt{ }} \href{https://ci.appveyor.com/project/jprichardson/node-fs-extra/branch/master}{\texttt{ }} \href{https://www.npmjs.org/package/fs-extra}{\texttt{ }} \href{https://coveralls.io/github/jprichardson/node-fs-extra}{\texttt{ }} \href{https://standardjs.com}{\texttt{ }}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29050}{}\doxysection{Why?}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29050}
I got tired of including {\ttfamily mkdirp}, {\ttfamily rimraf}, and {\ttfamily ncp} in most of my projects.\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29051}{}\doxysection{Installation}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29051}
\begin{DoxyVerb}npm install fs-extra
\end{DoxyVerb}
\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29052}{}\doxysection{Usage}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29052}
{\ttfamily fs-\/extra} is a drop in replacement for native {\ttfamily fs}. All methods in {\ttfamily fs} are attached to {\ttfamily fs-\/extra}. All {\ttfamily fs} methods return promises if the callback isn\textquotesingle{}t passed.

You don\textquotesingle{}t ever need to include the original {\ttfamily fs} module again\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs') // this is no longer necessary }

\end{DoxyCode}


you can now do this\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra') }

\end{DoxyCode}


or if you prefer to make it clear that you\textquotesingle{}re using {\ttfamily fs-\/extra} and not {\ttfamily fs}, you may want to name your {\ttfamily fs} variable {\ttfamily fse} like so\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const fse = require('fs-\/extra') }

\end{DoxyCode}


you can also keep both, but it\textquotesingle{}s redundant\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs')}
\DoxyCodeLine{const fse = require('fs-\/extra') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29053}{}\doxysection{Sync vs Async vs Async/\+Await}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29053}
Most methods are async by default. All async methods will return a promise if the callback isn\textquotesingle{}t passed.

Sync methods on the other hand will throw if an error occurs.

Also Async/\+Await will throw an error if one occurs.

Example\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{// Async with promises:}
\DoxyCodeLine{fs.copy('/tmp/myfile', '/tmp/mynewfile')}
\DoxyCodeLine{  .then(() => console.log('success!'))}
\DoxyCodeLine{  .catch(err => console.error(err))}
\DoxyCodeLine{}
\DoxyCodeLine{// Async with callbacks:}
\DoxyCodeLine{fs.copy('/tmp/myfile', '/tmp/mynewfile', err => \{}
\DoxyCodeLine{  if (err) return console.error(err)}
\DoxyCodeLine{  console.log('success!')}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// Sync:}
\DoxyCodeLine{try \{}
\DoxyCodeLine{  fs.copySync('/tmp/myfile', '/tmp/mynewfile')}
\DoxyCodeLine{  console.log('success!')}
\DoxyCodeLine{\} catch (err) \{}
\DoxyCodeLine{  console.error(err)}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{// Async/Await:}
\DoxyCodeLine{async function copyFiles () \{}
\DoxyCodeLine{  try \{}
\DoxyCodeLine{    await fs.copy('/tmp/myfile', '/tmp/mynewfile')}
\DoxyCodeLine{    console.log('success!')}
\DoxyCodeLine{  \} catch (err) \{}
\DoxyCodeLine{    console.error(err)}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{copyFiles() }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29054}{}\doxysection{Methods}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29054}
\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29055}{}\doxysubsection{Async}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29055}

\begin{DoxyItemize}
\item copy
\item empty\+Dir
\item ensure\+File
\item ensure\+Dir
\item ensure\+Link
\item ensure\+Symlink
\item mkdirp
\item mkdirs
\item move
\item output\+File
\item output\+Json
\item path\+Exists
\item read\+Json
\item remove
\item write\+Json
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29056}{}\doxysubsection{Sync}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29056}

\begin{DoxyItemize}
\item copy\+Sync
\item empty\+Dir\+Sync
\item ensure\+File\+Sync
\item ensure\+Dir\+Sync
\item ensure\+Link\+Sync
\item ensure\+Symlink\+Sync
\item mkdirp\+Sync
\item mkdirs\+Sync
\item move\+Sync
\item output\+File\+Sync
\item output\+Json\+Sync
\item path\+Exists\+Sync
\item read\+Json\+Sync
\item remove\+Sync
\item write\+Json\+Sync
\end{DoxyItemize}

{\bfseries{NOTE\+:}} You can still use the native Node.\+js methods. They are promisified and copied over to {\ttfamily fs-\/extra}. See notes on \`{}fs.read()\`{} \& \`{}fs.write()\`{}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29057}{}\doxysubsection{What happened to $<$tt$>$walk()$<$/tt$>$ and $<$tt$>$walk\+Sync()$<$/tt$>$?}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29057}
They were removed from {\ttfamily fs-\/extra} in v2.\+0.\+0. If you need the functionality, {\ttfamily walk} and {\ttfamily walk\+Sync} are available as separate packages, \href{https://github.com/jprichardson/node-klaw}{\texttt{ {\ttfamily klaw}}} and \href{https://github.com/manidlou/node-klaw-sync}{\texttt{ {\ttfamily klaw-\/sync}}}.\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29058}{}\doxysection{Third Party}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29058}
\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29059}{}\doxysubsection{Type\+Script}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29059}
If you like Type\+Script, you can use {\ttfamily fs-\/extra} with it\+: \href{https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/fs-extra}{\texttt{ https\+://github.\+com/\+Definitely\+Typed/\+Definitely\+Typed/tree/master/types/fs-\/extra}}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29060}{}\doxysubsection{File / Directory Watching}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29060}
If you want to watch for changes to files or directories, then you should use \href{https://github.com/paulmillr/chokidar}{\texttt{ chokidar}}.\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29061}{}\doxysubsection{Obtain Filesystem (\+Devices, Partitions) Information}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29061}
\href{https://github.com/arthurintelligence/node-fs-filesystem}{\texttt{ fs-\/filesystem}} allows you to read the state of the filesystem of the host on which it is run. It returns information about both the devices and the partitions (volumes) of the system.\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29062}{}\doxysubsection{Misc.}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29062}

\begin{DoxyItemize}
\item \href{https://github.com/jdxcode/fs-extra-debug}{\texttt{ fs-\/extra-\/debug}} -\/ Send your fs-\/extra calls to \href{https://npmjs.org/package/debug}{\texttt{ debug}}.
\item \href{https://github.com/cadorn/mfs}{\texttt{ mfs}} -\/ Monitor your fs-\/extra calls.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29063}{}\doxysection{Hacking on fs-\/extra}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29063}
Wanna hack on {\ttfamily fs-\/extra}? Great! Your help is needed! \href{http://nodei.co/npm/fs-extra.png?downloads=true&downloadRank=true&stars=true}{\texttt{ fs-\/extra is one of the most depended upon Node.\+js packages}}. This project uses \href{https://github.com/feross/standard}{\texttt{ Java\+Script Standard Style}} -\/ if the name or style choices bother you, you\textquotesingle{}re gonna have to get over it \+:) If {\ttfamily standard} is good enough for {\ttfamily npm}, it\textquotesingle{}s good enough for {\ttfamily fs-\/extra}.

\href{https://github.com/feross/standard}{\texttt{ }}

What\textquotesingle{}s needed?
\begin{DoxyItemize}
\item First, take a look at existing issues. Those are probably going to be where the priority lies.
\item More tests for edge cases. Specifically on different platforms. There can never be enough tests.
\item Improve test coverage. See coveralls output for more info.
\end{DoxyItemize}

Note\+: If you make any big changes, {\bfseries{you should definitely file an issue for discussion first.}}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29064}{}\doxysubsection{Running the Test Suite}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29064}
fs-\/extra contains hundreds of tests.


\begin{DoxyItemize}
\item {\ttfamily npm run lint}\+: runs the linter (\href{http://standardjs.com/}{\texttt{ standard}})
\item {\ttfamily npm run unit}\+: runs the unit tests
\item {\ttfamily npm test}\+: runs both the linter and the tests
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29065}{}\doxysubsection{Windows}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29065}
If you run the tests on the Windows and receive a lot of symbolic link {\ttfamily EPERM} permission errors, it\textquotesingle{}s because on Windows you need elevated privilege to create symbolic links. You can add this to your Windows\textquotesingle{}s account by following the instructions here\+: \href{http://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7}{\texttt{ http\+://superuser.\+com/questions/104845/permission-\/to-\/make-\/symbolic-\/links-\/in-\/windows-\/7}} However, I didn\textquotesingle{}t have much luck doing this.

Since I develop on Mac OS X, I use VMWare Fusion for Windows testing. I create a shared folder that I map to a drive on Windows. I open the {\ttfamily Node.\+js command prompt} and run as {\ttfamily Administrator}. I then map the network drive running the following command\+: \begin{DoxyVerb}net use z: "\\vmware-host\Shared Folders"
\end{DoxyVerb}
 I can then navigate to my {\ttfamily fs-\/extra} directory and run the tests.\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29066}{}\doxysection{Naming}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29066}
I put a lot of thought into the naming of these functions. Inspired by @coolaj86\textquotesingle{}s request. So he deserves much of the credit for raising the issue. See discussion(s) here\+:


\begin{DoxyItemize}
\item \href{https://github.com/jprichardson/node-fs-extra/issues/2}{\texttt{ https\+://github.\+com/jprichardson/node-\/fs-\/extra/issues/2}}
\item \href{https://github.com/flatiron/utile/issues/11}{\texttt{ https\+://github.\+com/flatiron/utile/issues/11}}
\item \href{https://github.com/ryanmcgrath/wrench-js/issues/29}{\texttt{ https\+://github.\+com/ryanmcgrath/wrench-\/js/issues/29}}
\item \href{https://github.com/substack/node-mkdirp/issues/17}{\texttt{ https\+://github.\+com/substack/node-\/mkdirp/issues/17}}
\end{DoxyItemize}

First, I believe that in as many cases as possible, the \href{http://nodejs.org/api/fs.html}{\texttt{ Node.\+js naming schemes}} should be chosen. However, there are problems with the Node.\+js own naming schemes.

For example, {\ttfamily fs.\+read\+File()} and {\ttfamily fs.\+readdir()}\+: the {\bfseries{F}} is capitalized in {\itshape File} and the {\bfseries{d}} is not capitalized in {\itshape dir}. Perhaps a bit pedantic, but they should still be consistent. Also, Node.\+js has chosen a lot of POSIX naming schemes, which I believe is great. See\+: {\ttfamily fs.\+mkdir()}, {\ttfamily fs.\+rmdir()}, {\ttfamily fs.\+chown()}, etc.

We have a dilemma though. How do you consistently name methods that perform the following POSIX commands\+: {\ttfamily cp}, {\ttfamily cp -\/r}, {\ttfamily mkdir -\/p}, and {\ttfamily rm -\/rf}?

My perspective\+: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. So when you want to copy it or remove it, in most cases you\textquotesingle{}ll want to copy or remove all of its contents. When you want to create a directory, if the directory that it\textquotesingle{}s suppose to be contained in does not exist, then in most cases you\textquotesingle{}ll want to create that too.

So, if you want to remove a file or a directory regardless of whether it has contents, just call {\ttfamily fs.\+remove(path)}. If you want to copy a file or a directory whether it has contents, just call {\ttfamily fs.\+copy(source, destination)}. If you want to create a directory regardless of whether its parent directories exist, just call {\ttfamily fs.\+mkdirs(path)} or {\ttfamily fs.\+mkdirp(path)}.\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29067}{}\doxysection{Credit}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29067}
{\ttfamily fs-\/extra} wouldn\textquotesingle{}t be possible without using the modules from the following authors\+:


\begin{DoxyItemize}
\item \href{https://github.com/isaacs}{\texttt{ Isaac Shlueter}}
\item \href{https://github.com/avianflu}{\texttt{ Charlie Mc\+Connel}}
\item \href{https://github.com/substack}{\texttt{ James Halliday}}
\item \href{https://github.com/andrewrk}{\texttt{ Andrew Kelley}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29068}{}\doxysection{License}\label{md_sfcode_node_modules_streamroller_node_modules_fs_extra_README_autotoc_md29068}
Licensed under MIT

Copyright (c) 2011-\/2017 \href{https://github.com/jprichardson}{\texttt{ JP Richardson}} 