{\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 should be a drop in replacement for {\ttfamily fs}.

\href{https://www.npmjs.org/package/fs-extra}{\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/r/jprichardson/node-fs-extra}{\texttt{ }}

\href{https://github.com/feross/standard}{\texttt{ }}\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11048}{}\doxysection{Why?}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11048}
I got tired of including {\ttfamily mkdirp}, {\ttfamily rimraf}, and {\ttfamily ncp} in most of my projects.\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11049}{}\doxysection{Installation}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11049}
\begin{DoxyVerb}npm install --save fs-extra
\end{DoxyVerb}
\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11050}{}\doxysection{Usage}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11050}
{\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_fs_extra_README_autotoc_md11051}{}\doxysection{Sync vs Async}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11051}
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.

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{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11052}{}\doxysection{Methods}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11052}
\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11053}{}\doxysubsection{Async}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11053}

\begin{DoxyItemize}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_copy}{copy}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_emptyDir}{empty\+Dir}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureFile}{ensure\+File}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureDir}{ensure\+Dir}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureLink}{ensure\+Link}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureSymlink}{ensure\+Symlink}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureDir}{mkdirs}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_move}{move}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_outputFile}{output\+File}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_outputJson}{output\+Json}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_pathExists}{path\+Exists}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_readJson}{read\+Json}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_remove}{remove}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_writeJson}{write\+Json}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11054}{}\doxysubsection{Sync}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11054}

\begin{DoxyItemize}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_copy_sync}{copy\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_emptyDir_sync}{empty\+Dir\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureFile_sync}{ensure\+File\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureDir_sync}{ensure\+Dir\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureLink_sync}{ensure\+Link\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureSymlink_sync}{ensure\+Symlink\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_ensureDir_sync}{mkdirs\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_move_sync}{move\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_outputFile_sync}{output\+File\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_outputJson_sync}{output\+Json\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_pathExists_sync}{path\+Exists\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_readJson_sync}{read\+Json\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_remove_sync}{remove\+Sync}}
\item \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_writeJson_sync}{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 \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_fs_read_write}{notes on \`{}fs.read()\`{} \& \`{}fs.write()\`{}}}\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11055}{}\doxysubsection{What happened to $<$tt$>$walk()$<$/tt$>$ and $<$tt$>$walk\+Sync()$<$/tt$>$?}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11055}
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_fs_extra_README_autotoc_md11056}{}\doxysection{Third Party}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11056}
\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11057}{}\doxysubsection{Type\+Script}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11057}
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_fs_extra_README_autotoc_md11058}{}\doxysubsection{File / Directory Watching}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11058}
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_fs_extra_README_autotoc_md11059}{}\doxysubsection{Misc.}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11059}

\begin{DoxyItemize}
\item \href{https://github.com/cadorn/mfs}{\texttt{ mfs}} -\/ Monitor your fs-\/extra calls.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_fs_extra_README_autotoc_md11060}{}\doxysection{Hacking on fs-\/extra}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11060}
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_fs_extra_README_autotoc_md11061}{}\doxysubsection{Running the Test Suite}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11061}
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_fs_extra_README_autotoc_md11062}{}\doxysubsection{Windows}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11062}
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_fs_extra_README_autotoc_md11063}{}\doxysection{Naming}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11063}
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_fs_extra_README_autotoc_md11064}{}\doxysection{Credit}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11064}
{\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_fs_extra_README_autotoc_md11065}{}\doxysection{License}\label{md_sfcode_node_modules_fs_extra_README_autotoc_md11065}
Licensed under MIT

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