@types/fs-extra

  • Version 11.0.4
  • Published
  • 36.8 kB
  • 2 dependencies
  • MIT license

Install

npm i @types/fs-extra
yarn add @types/fs-extra
pnpm add @types/fs-extra

Overview

TypeScript definitions for fs-extra

Index

Variables

variable access

const access: any;

    variable appendFile

    const appendFile: any;

      variable chmod

      const chmod: any;

        variable chown

        const chown: any;

          variable close

          const close: any;

            variable copyFile

            const copyFile: any;

              variable createFile

              const createFile: {
              (file: string): Promise<void>;
              (file: string, callback: NoParamCallbackWithUndefined): void;
              };
              • See Also

                • ensureFile

              variable createFileSync

              const createFileSync: (file: string) => void;
              • See Also

                • ensureFileSync

              const createLink: {
              (src: string, dest: string): Promise<void>;
              (src: string, dest: string, callback: fs.NoParamCallback): void;
              };
              • See Also

                • ensureLink

              variable createLinkSync

              const createLinkSync: (src: string, dest: string) => void;
              • See Also

                • ensureLinkSync

              const createSymlink: {
              (src: string, dest: string, type?: fs.symlink.Type): Promise<void>;
              (src: string, dest: string, callback: fs.NoParamCallback): void;
              (
              src: string,
              dest: string,
              type: fs.symlink.Type,
              callback: fs.NoParamCallback
              ): void;
              };
              • See Also

                • ensureSymlink

              variable createSymlinkSync

              const createSymlinkSync: (src: string, dest: string, type?: fs.symlink.Type) => void;
              • See Also

                • ensureSymlinkSync

              variable emptydir

              const emptydir: {
              (path: string): Promise<void>;
              (path: string, callback: fs.NoParamCallback): void;
              };
              • See Also

                • emptyDir

              variable emptydirSync

              const emptydirSync: (path: string) => void;
              • See Also

                • emptyDirSync

              variable exists

              const exists: any;

                variable fchmod

                const fchmod: any;

                  variable fchown

                  const fchown: any;

                    variable fdatasync

                    const fdatasync: any;

                      variable fstat

                      const fstat: any;

                        variable fsync

                        const fsync: any;

                          variable ftruncate

                          const ftruncate: any;

                            variable futimes

                            const futimes: any;

                              variable lchmod

                              const lchmod: any;

                                variable lchown

                                const lchown: any;
                                  const link: any;

                                    variable lstat

                                    const lstat: any;

                                      variable mkdir

                                      const mkdir: any;

                                        variable mkdirp

                                        const mkdirp: {
                                        (path: string, options?: number | EnsureDirOptions): Promise<void>;
                                        (path: string, callback: fs.NoParamCallback): void;
                                        (
                                        path: string,
                                        options: number | EnsureDirOptions,
                                        callback: fs.NoParamCallback
                                        ): void;
                                        };
                                        • See Also

                                          • ensureDir

                                        variable mkdirpSync

                                        const mkdirpSync: (path: string, options?: number | EnsureDirOptions) => void;
                                        • See Also

                                          • ensureDirSync

                                        variable mkdirs

                                        const mkdirs: {
                                        (path: string, options?: number | EnsureDirOptions): Promise<void>;
                                        (path: string, callback: fs.NoParamCallback): void;
                                        (
                                        path: string,
                                        options: number | EnsureDirOptions,
                                        callback: fs.NoParamCallback
                                        ): void;
                                        };
                                        • See Also

                                          • ensureDir

                                        variable mkdirsSync

                                        const mkdirsSync: (path: string, options?: number | EnsureDirOptions) => void;
                                        • See Also

                                          • ensureDirSync

                                        variable mkdtemp

                                        const mkdtemp: any;

                                          variable open

                                          const open: any;

                                            variable opendir

                                            const opendir: any;

                                              variable outputJSON

                                              const outputJSON: {
                                              (file: string, data: any, options?: any): Promise<void>;
                                              (file: string, data: any, options: any, callback: fs.NoParamCallback): void;
                                              (file: string, data: any, callback: fs.NoParamCallback): void;
                                              };
                                              • See Also

                                                • outputJson

                                              variable outputJSONSync

                                              const outputJSONSync: (file: string, data: any, options?: any) => void;
                                              • See Also

                                                • outputJsonSync

                                              variable read

                                              const read: any;

                                                variable readdir

                                                const readdir: any;

                                                  variable readFile

                                                  const readFile: any;

                                                    variable readJson

                                                    const readJson: any;
                                                    • Reads a JSON file and then parses it into an object.

                                                      Example 1

                                                      import * as fs from 'fs-extra'

                                                      // With a callback: fs.readJson('./package.json', (err, packageObj) => { if (err) console.error(err) console.log(packageObj.version) // => 0.1.3 })

                                                      // With Promises: fs.readJson('./package.json') .then(packageObj => { console.log(packageObj.version) // => 0.1.3 }) .catch(err => { console.error(err) })

                                                      // With async/await: async function asyncAwait () { try { const packageObj = await fs.readJson('./package.json') console.log(packageObj.version) // => 0.1.3 } catch (err) { console.error(err) } }

                                                      asyncAwait()

                                                      // readJsonSync() can take a throws option set to false and it won't throw if the JSON is invalid. Example: const file = '/tmp/some-invalid.json' const data = '{not valid JSON' fs.writeFileSync(file, data)

                                                      // With a callback: fs.readJson(file, { throws: false }, (err, obj) => { if (err) console.error(err) console.log(obj) // => null })

                                                      // With Promises: fs.readJson(file, { throws: false }) .then(obj => { console.log(obj) // => null }) .catch(err => { console.error(err) // Not called })

                                                      // With async/await: async function asyncAwaitThrows () { const obj = await fs.readJson(file, { throws: false }) console.log(obj) // => null }

                                                      asyncAwaitThrows()

                                                    variable readJSON

                                                    const readJSON: any;
                                                    • See Also

                                                      • readJson

                                                    variable readJsonSync

                                                    const readJsonSync: any;
                                                    • Reads a JSON file and then parses it into an object.

                                                      Example 1

                                                      import * as fs from 'fs-extra'

                                                      const packageObj = fs.readJsonSync('./package.json') console.log(packageObj.version) // => 2.0.0

                                                      // readJsonSync() can take a throws option set to false and it won't throw if the JSON is invalid. Example: const file = '/tmp/some-invalid.json' const data = '{not valid JSON' fs.writeFileSync(file, data)

                                                      const obj = fs.readJsonSync(file, { throws: false }) console.log(obj) // => null

                                                    variable readJSONSync

                                                    const readJSONSync: any;
                                                    • See Also

                                                      • readJsonSync

                                                    const readlink: any;

                                                      variable readv

                                                      const readv: any;

                                                        variable realpath

                                                        const realpath: any;

                                                          variable rename

                                                          const rename: any;

                                                            variable rm

                                                            const rm: any;

                                                              variable rmdir

                                                              const rmdir: any;

                                                                variable stat

                                                                const stat: any;
                                                                  const symlink: any;

                                                                    variable truncate

                                                                    const truncate: any;
                                                                      const unlink: any;

                                                                        variable utimes

                                                                        const utimes: any;

                                                                          variable write

                                                                          const write: any;

                                                                            variable writeFile

                                                                            const writeFile: any;

                                                                              variable writeJson

                                                                              const writeJson: any;
                                                                              • Writes an object to a JSON file.

                                                                                Example 1

                                                                                import * as fs from 'fs-extra'

                                                                                // With a callback: fs.writeJson('./package.json', {name: 'fs-extra'}, err => { if (err) return console.error(err) console.log('success!') })

                                                                                // With Promises: fs.writeJson('./package.json', {name: 'fs-extra'}) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                // With async/await: async function asyncAwait () { try { await fs.writeJson('./package.json', {name: 'fs-extra'}) console.log('success!') } catch (err) { console.error(err) } }

                                                                                asyncAwait()

                                                                              variable writeJSON

                                                                              const writeJSON: any;
                                                                              • See Also

                                                                                • writeJson

                                                                              variable writeJsonSync

                                                                              const writeJsonSync: any;
                                                                              • Writes an object to a JSON file.

                                                                                Example 1

                                                                                import * as fs from 'fs-extra'

                                                                                fs.writeJsonSync('./package.json', {name: 'fs-extra'})

                                                                              variable writeJSONSync

                                                                              const writeJSONSync: any;
                                                                              • See Also

                                                                                • writeJsonSync

                                                                              variable writev

                                                                              const writev: any;

                                                                                Functions

                                                                                function copy

                                                                                copy: {
                                                                                (src: string, dest: string, options?: CopyOptions): Promise<void>;
                                                                                (src: string, dest: string, callback: NoParamCallbackWithUndefined): void;
                                                                                (
                                                                                src: string,
                                                                                dest: string,
                                                                                options: CopyOptions,
                                                                                callback: NoParamCallbackWithUndefined
                                                                                ): void;
                                                                                };
                                                                                • Copy a file or directory. The directory can have contents.

                                                                                  Parameter src

                                                                                  Note that if src is a directory it will copy everything inside of this directory, not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).

                                                                                  Parameter dest

                                                                                  Note that if src is a file, dest cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  // With a callback: fs.copy('/tmp/myfile', '/tmp/mynewfile', err => { if (err) return console.error(err) console.log('success!') }) // copies file

                                                                                  fs.copy('/tmp/mydir', '/tmp/mynewdir', err => { if (err) return console.error(err) console.log('success!') }) // copies directory, even if it has subdirectories or files

                                                                                  // With Promises: fs.copy('/tmp/myfile', '/tmp/mynewfile') .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.copy('/tmp/myfile', '/tmp/mynewfile') console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                  // Using filter function fs.copy( '/tmp/mydir', '/tmp/mynewdir', { filter(src, dest) { // your logic here // it will be copied if return true } }, err => { if (err) return console.error(err) console.log('success!') } )

                                                                                function copySync

                                                                                copySync: (src: string, dest: string, options?: CopyOptionsSync) => void;
                                                                                • Copy a file or directory. The directory can have contents.

                                                                                  Parameter src

                                                                                  Note that if src is a directory it will copy everything inside of this directory, not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).

                                                                                  Parameter dest

                                                                                  Note that if src is a file, dest cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  // copy file fs.copySync('/tmp/myfile', '/tmp/mynewfile')

                                                                                  // copy directory, even if it has subdirectories or files fs.copySync('/tmp/mydir', '/tmp/mynewdir')

                                                                                  // Using filter function fs.copySync('/tmp/mydir', '/tmp/mynewdir', { filter(src, dest) { // your logic here // it will be copied if return true } })

                                                                                function emptyDir

                                                                                emptyDir: {
                                                                                (path: string): Promise<void>;
                                                                                (path: string, callback: fs.NoParamCallback): void;
                                                                                };
                                                                                • Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  // assume this directory has a lot of files and folders // With a callback: fs.emptyDir('/tmp/some/dir', err => { if (err) return console.error(err) console.log('success!') })

                                                                                  // With Promises: fs.emptyDir('/tmp/some/dir') .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.emptyDir('/tmp/some/dir') console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function emptyDirSync

                                                                                emptyDirSync: (path: string) => void;
                                                                                • Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  // assume this directory has a lot of files and folders fs.emptyDirSync('/tmp/some/dir')

                                                                                function ensureDir

                                                                                ensureDir: {
                                                                                (path: string, options?: EnsureDirOptions | number): Promise<void>;
                                                                                (path: string, callback: fs.NoParamCallback): void;
                                                                                (
                                                                                path: string,
                                                                                options: number | EnsureDirOptions,
                                                                                callback: fs.NoParamCallback
                                                                                ): void;
                                                                                };
                                                                                • Ensures that the directory exists. If the directory structure does not exist, it is created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const dir = '/tmp/this/path/does/not/exist' const desiredMode = 0o2775 const options = { mode: 0o2775 }

                                                                                  // With a callback: fs.ensureDir(dir, err => { console.log(err) // => null // dir has now been created, including the directory it is to be placed in })

                                                                                  // With a callback and a mode integer fs.ensureDir(dir, desiredMode, err => { console.log(err) // => null // dir has now been created with mode 0o2775, including the directory it is to be placed in })

                                                                                  // With Promises: fs.ensureDir(dir) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With Promises and a mode integer: fs.ensureDir(dir, desiredMode) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.ensureDir(dir) console.log('success!') } catch (err) { console.error(err) } } asyncAwait()

                                                                                  // With async/await and an options object, containing mode: async function asyncAwaitMode () { try { await fs.ensureDir(dir, options) console.log('success!') } catch (err) { console.error(err) } } asyncAwaitMode()

                                                                                function ensureDirSync

                                                                                ensureDirSync: (path: string, options?: EnsureDirOptions | number) => void;
                                                                                • Ensures that the directory exists. If the directory structure does not exist, it is created. If provided, options may specify the desired mode for the directory.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const dir = '/tmp/this/path/does/not/exist'

                                                                                  const desiredMode = 0o2775 const options = { mode: 0o2775 }

                                                                                  fs.ensureDirSync(dir) // dir has now been created, including the directory it is to be placed in

                                                                                  fs.ensureDirSync(dir, desiredMode) // dir has now been created, including the directory it is to be placed in with permission 0o2775

                                                                                  fs.ensureDirSync(dir, options) // dir has now been created, including the directory it is to be placed in with permission 0o2775

                                                                                function ensureFile

                                                                                ensureFile: {
                                                                                (file: string): Promise<void>;
                                                                                (file: string, callback: NoParamCallbackWithUndefined): void;
                                                                                };
                                                                                • Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.txt'

                                                                                  // With a callback: fs.ensureFile(file, err => { console.log(err) // => null // file has now been created, including the directory it is to be placed in })

                                                                                  // With Promises: fs.ensureFile(file) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.ensureFile(file) console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function ensureFileSync

                                                                                ensureFileSync: (file: string) => void;
                                                                                • Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.txt' fs.ensureFileSync(file) // file has now been created, including the directory it is to be placed in

                                                                                ensureLink: {
                                                                                (src: string, dest: string): Promise<void>;
                                                                                (src: string, dest: string, callback: fs.NoParamCallback): void;
                                                                                };
                                                                                • Ensures that the link exists. If the directory structure does not exist, it is created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const srcPath = '/tmp/file.txt' const destPath = '/tmp/this/path/does/not/exist/file.txt'

                                                                                  // With a callback: fs.ensureLink(srcPath, destPath, err => { console.log(err) // => null // link has now been created, including the directory it is to be placed in })

                                                                                  // With Promises: fs.ensureLink(srcPath, destPath) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.ensureLink(srcPath, destPath) console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function ensureLinkSync

                                                                                ensureLinkSync: (src: string, dest: string) => void;
                                                                                • Ensures that the link exists. If the directory structure does not exist, it is created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const srcPath = '/tmp/file.txt' const destPath = '/tmp/this/path/does/not/exist/file.txt' fs.ensureLinkSync(srcPath, destPath) // link has now been created, including the directory it is to be placed in

                                                                                ensureSymlink: {
                                                                                (src: string, dest: string, type?: fs.symlink.Type): Promise<void>;
                                                                                (src: string, dest: string, callback: fs.NoParamCallback): void;
                                                                                (
                                                                                src: string,
                                                                                dest: string,
                                                                                type: fs.symlink.Type,
                                                                                callback: fs.NoParamCallback
                                                                                ): void;
                                                                                };
                                                                                • Ensures that the symlink exists. If the directory structure does not exist, it is created.

                                                                                  Parameter type

                                                                                  It is only available on Windows and ignored on other platforms.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const srcPath = '/tmp/file.txt' const destPath = '/tmp/this/path/does/not/exist/file.txt'

                                                                                  // With a callback: fs.ensureSymlink(srcPath, destPath, err => { console.log(err) // => null // symlink has now been created, including the directory it is to be placed in })

                                                                                  // With Promises: fs.ensureSymlink(srcPath, destPath) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.ensureSymlink(srcPath, destPath) console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function ensureSymlinkSync

                                                                                ensureSymlinkSync: (src: string, dest: string, type?: fs.symlink.Type) => void;
                                                                                • Ensures that the symlink exists. If the directory structure does not exist, it is created.

                                                                                  Parameter type

                                                                                  It is only available on Windows and ignored on other platforms.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const srcPath = '/tmp/file.txt' const destPath = '/tmp/this/path/does/not/exist/file.txt' fs.ensureSymlinkSync(srcPath, destPath) // symlink has now been created, including the directory it is to be placed in

                                                                                function move

                                                                                move: {
                                                                                (src: string, dest: string, options?: MoveOptions): Promise<void>;
                                                                                (src: string, dest: string, callback: NoParamCallbackWithUndefined): void;
                                                                                (
                                                                                src: string,
                                                                                dest: string,
                                                                                options: MoveOptions,
                                                                                callback: NoParamCallbackWithUndefined
                                                                                ): void;
                                                                                };
                                                                                • Moves a file or directory, even across devices.

                                                                                  Parameter dest

                                                                                  Note: When src is a file, dest must be a file and when src is a directory, dest must be a directory.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const src = '/tmp/file.txt' const dest = '/tmp/this/path/does/not/exist/file.txt'

                                                                                  // With a callback: fs.move(src, dest, err => { if (err) return console.error(err) console.log('success!') })

                                                                                  // With Promises: fs.move(src, dest) .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.move(src, dest) console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                  // Using overwrite option fs.move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => { if (err) return console.error(err) console.log('success!') })

                                                                                function moveSync

                                                                                moveSync: (src: string, dest: string, options?: MoveOptions) => void;
                                                                                • Moves a file or directory, even across devices.

                                                                                  Parameter dest

                                                                                  Note: When src is a file, dest must be a file and when src is a directory, dest must be a directory.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  fs.moveSync('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')

                                                                                  // Using overwrite option fs.moveSync('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true })

                                                                                function outputFile

                                                                                outputFile: {
                                                                                (
                                                                                file: string,
                                                                                data: string | NodeJS.ArrayBufferView,
                                                                                options?: fs.WriteFileOptions
                                                                                ): Promise<void>;
                                                                                (file: string, data: any, callback: fs.NoParamCallback): void;
                                                                                (
                                                                                file: string,
                                                                                data: any,
                                                                                options: fs.WriteFileOptions,
                                                                                callback: fs.NoParamCallback
                                                                                ): void;
                                                                                };
                                                                                • Almost the same as writeFile (i.e. it overwrites), except that if the parent directory does not exist, it's created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.txt'

                                                                                  // With a callback: fs.outputFile(file, 'hello!', err => { console.log(err) // => null

                                                                                  fs.readFile(file, 'utf8', (err, data) => { if (err) return console.error(err) console.log(data) // => hello! }) })

                                                                                  // With Promises: fs.outputFile(file, 'hello!') .then(() => fs.readFile(file, 'utf8')) .then(data => { console.log(data) // => hello! }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.outputFile(file, 'hello!')

                                                                                  const data = await fs.readFile(file, 'utf8')

                                                                                  console.log(data) // => hello! } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function outputFileSync

                                                                                outputFileSync: (
                                                                                file: string,
                                                                                data: string | NodeJS.ArrayBufferView,
                                                                                options?: fs.WriteFileOptions
                                                                                ) => void;
                                                                                • Almost the same as writeFileSync (i.e. it overwrites), except that if the parent directory does not exist, it's created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.txt' fs.outputFileSync(file, 'hello!')

                                                                                  const data = fs.readFileSync(file, 'utf8') console.log(data) // => hello!

                                                                                function outputJson

                                                                                outputJson: {
                                                                                (file: string, data: any, options?: JsonOutputOptions): Promise<void>;
                                                                                (file: string, data: any, options: any, callback: fs.NoParamCallback): void;
                                                                                (file: string, data: any, callback: fs.NoParamCallback): void;
                                                                                };
                                                                                • Almost the same as writeJson, except that if the directory does not exist, it's created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.json'

                                                                                  // With a callback: fs.outputJson(file, {name: 'JP'}, err => { console.log(err) // => null

                                                                                  fs.readJson(file, (err, data) => { if (err) return console.error(err) console.log(data.name) // => JP }) })

                                                                                  // With Promises: fs.outputJson(file, {name: 'JP'}) .then(() => fs.readJson(file)) .then(data => { console.log(data.name) // => JP }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.outputJson(file, {name: 'JP'})

                                                                                  const data = await fs.readJson(file)

                                                                                  console.log(data.name) // => JP } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function outputJsonSync

                                                                                outputJsonSync: (file: string, data: any, options?: JsonOutputOptions) => void;
                                                                                • Almost the same as writeJsonSync, except that if the directory does not exist, it's created.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.json' fs.outputJsonSync(file, {name: 'JP'})

                                                                                  const data = fs.readJsonSync(file) console.log(data.name) // => JP

                                                                                function pathExists

                                                                                pathExists: {
                                                                                (path: string): Promise<boolean>;
                                                                                (path: string, callback: (err: any, exists: boolean) => void): void;
                                                                                };
                                                                                • Test whether or not the given path exists by checking with the file system. Like [fs.exists](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback), but with a normal callback signature (err, exists). Uses fs.access under the hood.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  const file = '/tmp/this/path/does/not/exist/file.txt'

                                                                                  // With a callback: fs.pathExists(file, (err, exists) => { console.log(err) // => null console.log(exists) // => false })

                                                                                  // Promise usage: fs.pathExists(file) .then(exists => console.log(exists)) // => false

                                                                                  // With async/await: async function asyncAwait () { const exists = await fs.pathExists(file)

                                                                                  console.log(exists) // => false }

                                                                                  asyncAwait()

                                                                                function pathExistsSync

                                                                                pathExistsSync: (path: string) => boolean;
                                                                                • An alias for [fs.existsSync](https://nodejs.org/api/fs.html#fs_fs_existssync_path), created for consistency with pathExists.

                                                                                function remove

                                                                                remove: {
                                                                                (dir: string): Promise<void>;
                                                                                (dir: string, callback: fs.NoParamCallback): void;
                                                                                };
                                                                                • Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  // remove file // With a callback: fs.remove('/tmp/myfile', err => { if (err) return console.error(err) console.log('success!') })

                                                                                  fs.remove('/home/jprichardson', err => { if (err) return console.error(err) console.log('success!') // I just deleted my entire HOME directory. })

                                                                                  // With Promises: fs.remove('/tmp/myfile') .then(() => { console.log('success!') }) .catch(err => { console.error(err) })

                                                                                  // With async/await: async function asyncAwait () { try { await fs.remove('/tmp/myfile') console.log('success!') } catch (err) { console.error(err) } }

                                                                                  asyncAwait()

                                                                                function removeSync

                                                                                removeSync: (dir: string) => void;
                                                                                • Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.

                                                                                  Example 1

                                                                                  import * as fs from 'fs-extra'

                                                                                  // remove file fs.removeSync('/tmp/myfile')

                                                                                  fs.removeSync('/home/jprichardson') // I just deleted my entire HOME directory.

                                                                                Interfaces

                                                                                interface CopyOptions

                                                                                interface CopyOptions {}

                                                                                  property dereference

                                                                                  dereference?: boolean | undefined;
                                                                                  • Dereference symlinks. false

                                                                                  property errorOnExist

                                                                                  errorOnExist?: boolean | undefined;
                                                                                  • When overwrite is false and the destination exists, throw an error. false

                                                                                  property filter

                                                                                  filter?: CopyFilterSync | CopyFilterAsync | undefined;
                                                                                  • Function to filter copied files/directories. Return true to copy the item, false to ignore it. Can also return a Promise that resolves to true or false (or pass in an async function).

                                                                                  property overwrite

                                                                                  overwrite?: boolean | undefined;
                                                                                  • Overwrite existing file or directory. _Note that the copy operation will silently fail if you set this to false and the destination exists._ Use the errorOnExist option to change this behavior. true

                                                                                  property preserveTimestamps

                                                                                  preserveTimestamps?: boolean | undefined;
                                                                                  • When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. false

                                                                                  interface CopyOptionsSync

                                                                                  interface CopyOptionsSync extends CopyOptions {}

                                                                                    property filter

                                                                                    filter?: CopyFilterSync | undefined;
                                                                                    • Function to filter copied files/directories. Return true to copy the item, false to ignore it.

                                                                                    interface EnsureDirOptions

                                                                                    interface EnsureDirOptions {}

                                                                                      property mode

                                                                                      mode?: number | undefined;

                                                                                        interface MoveOptions

                                                                                        interface MoveOptions {}

                                                                                          property dereference

                                                                                          dereference?: boolean | undefined;
                                                                                          • Dereference symlinks. false

                                                                                          property overwrite

                                                                                          overwrite?: boolean | undefined;
                                                                                          • Overwrite existing file or directory. false

                                                                                          Type Aliases

                                                                                          type CopyFilterAsync

                                                                                          type CopyFilterAsync = (src: string, dest: string) => Promise<boolean>;

                                                                                            type CopyFilterSync

                                                                                            type CopyFilterSync = (src: string, dest: string) => boolean;

                                                                                              type JsonOutputOptions

                                                                                              type JsonOutputOptions = fs.WriteFileOptions & StringifyOptions;

                                                                                                type NoParamCallbackWithUndefined

                                                                                                type NoParamCallbackWithUndefined = (
                                                                                                err: NodeJS.ErrnoException | null | undefined
                                                                                                ) => void;

                                                                                                  type SymlinkType

                                                                                                  type SymlinkType = fs.symlink.Type;

                                                                                                    Package Files (1)

                                                                                                    Dependencies (2)

                                                                                                    Dev Dependencies (0)

                                                                                                    No dev dependencies.

                                                                                                    Peer Dependencies (0)

                                                                                                    No peer dependencies.

                                                                                                    Badge

                                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/fs-extra.

                                                                                                    • Markdown
                                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/fs-extra)
                                                                                                    • HTML
                                                                                                      <a href="https://www.jsdocs.io/package/@types/fs-extra"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>