fs-extra
semver
>=9.0.0 <12.0.0postconditions26functions12last verified2026-04-06coverage score100%Postconditions — what we check
- readJson · file-not-founderrorWhenFile at path does not existThrows
Error with code ENOENTRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOENT' to handle missing files. Consider using pathExists() first or providing a default value in the catch block.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - readJson · invalid-jsonerrorWhenFile exists but contains invalid JSONThrows
SyntaxErrorRequired handlingCaller MUST wrap in try-catch. Invalid JSON throws a SyntaxError (not an Error with a code). Validate JSON structure after reading if schema compliance is required.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - readJson · permission-deniederrorWhenProcess lacks read permission for the fileThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' to handle permission errors. Ensure the process has appropriate filesystem permissions.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - copy · source-not-founderrorWhenSource path does not existThrows
Error with code ENOENTRequired handlingCaller MUST wrap in try-catch. Verify source exists before copying, or handle ENOENT in the catch block. Consider using pathExists() to pre-check source existence.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - copy · permission-deniederrorWhenProcess lacks read permission on source or write permission on destinationThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' and handle appropriately. Ensure the process has read access to source and write access to destination parent.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - move · source-not-founderrorWhenSource path does not existThrows
Error with code ENOENTRequired handlingCaller MUST wrap in try-catch. Handle ENOENT for missing source path. Consider using pathExists() to pre-check source existence.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[3] - move · destination-existserrorWhenDestination already exists and overwrite option is not set to trueThrows
Error: dest already exists.Required handlingCaller MUST either pass { overwrite: true } option to allow overwriting, or wrap in try-catch to handle the case where destination already exists. Note: the default for move (overwrite: false) differs from copy (overwrite: true) — a common footgun.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[3] - move · permission-deniederrorWhenProcess lacks write permission on source or destinationThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' and handle appropriately.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[3] - outputFile · outputfile-permission-deniederrorWhenProcess lacks write permission on the target file or a parent directory componentThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' to handle permission errors. SaaS apps often run as restricted users without write access to all paths. Particularly dangerous in background jobs where the error is silently discarded.costmediumin prodimmediate exceptionusers seelost datavisibilitysilent - outputFile · outputfile-disk-fullerrorWhenFilesystem has no remaining space when fs.writeFile is calledThrows
Error with code ENOSPCRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOSPC' to detect disk-full conditions. Unlike EACCES (predictable at startup), disk-full is a runtime error. Monitoring disk space and handling ENOSPC is critical for any app writing user files.costhighin prodimmediate exceptionusers seelost datavisibilitysilent - writeJson · writejson-parent-not-founderrorWhenParent directory does not exist (writeJson does not create parent directories)Throws
Error with code ENOENTRequired handlingCaller MUST wrap in try-catch. Unlike outputJson/outputFile, writeJson does NOT create missing parent directories. Use outputJson() if the parent directory may not exist. Handle ENOENT in the catch block to detect missing parent directories.costmediumin prodimmediate exceptionusers seelost datavisibilitysilent - writeJson · writejson-permission-deniederrorWhenProcess lacks write permission on the target file or parent directoryThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' to handle permission errors. Propagates directly from fs.writeFile.costmediumin prodimmediate exceptionusers seelost datavisibilitysilent - writeJson · writejson-circular-referenceerrorWhenData object contains circular references (e.g. ORM model, Express req/res object)Throws
TypeError: Converting circular structure to JSONRequired handlingCaller MUST wrap in try-catch. TypeError from circular references does not have a code property — check for TypeError or the message text. Avoid serializing ORM model instances, class objects with parent references, or Express req/res objects directly.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - ensureDir · ensuredir-permission-deniederrorWhenProcess lacks write or execute permission on a parent directory componentThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' to handle permission errors. Directory creation fails — subsequent file writes to that path will also fail with ENOENT. Ensure the process has write permission on all parent directory components.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilitysilent - ensureDir · ensuredir-path-component-is-fileerrorWhenA component of the path that should be a directory is actually an existing fileThrows
Error with code ENOTDIRRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOTDIR' to detect path conflicts. This occurs in misconfigured deployments where a directory path collides with an existing file (e.g. '/data/config' is a file but caller expects a directory).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - remove · remove-permission-deniederrorWhenProcess lacks write permission on the file or directory, or execute permission on a parent directoryThrows
Error with code EACCES (Unix) or EPERM (Windows)Required handlingCaller MUST wrap in try-catch. The force: true option ONLY silences ENOENT — it does NOT silence permission errors. Check error.code === 'EACCES' || error.code === 'EPERM'. Failed cleanup leaves orphaned files on disk with no alert.costmediumin prodimmediate exceptionusers seelost datavisibilitysilent - outputJson · outputjson-circular-referenceerrorWhenData object contains circular references (e.g. ORM model instances, Express objects)Throws
TypeError: Converting circular structure to JSONRequired handlingCaller MUST wrap in try-catch. TypeError occurs before any file I/O — no file is created or modified. The error has no code property, making it harder to detect in generic catch blocks. Avoid serializing class instances or cyclic object graphs.costmediumin prodimmediate exceptionusers seelost datavisibilitysilent - outputJson · outputjson-permission-deniederrorWhenProcess lacks write permission on the target file or any parent directoryThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES'. Inherits from outputFile → fs.writeFile. Silent failure leaves system in stale state.costmediumin prodimmediate exceptionusers seelost datavisibilitysilent - ensureFile · ensurefile-permission-deniederrorWhenProcess lacks write permission on the target directory or execute permission on a parentThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES'. Parent directory creation propagates EACCES unmodified. Common in init scripts that create log or pid files in permission-restricted paths.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilitysilent - ensureFile · ensurefile-path-component-is-fileerrorWhenA component of the path that should be a directory is actually an existing fileThrows
Error with code ENOTDIRRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOTDIR'. The source explicitly calls fs.readdir(dir) to trigger ENOTDIR when the parent stat shows it is not a directory. Common in misconfigured deployments where a path component is a file, not a directory.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[16] - mkdirp · mkdirp-permission-deniederrorWhenProcess lacks write or execute permission on a parent directory componentThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' to handle permission errors. mkdirp() is identical to ensureDir() — both call fs.mkdir({recursive: true}) via makeDir. Directory creation fails — subsequent file writes to that path will also fail with ENOENT. Ensure the process has write permission on all parent directory components.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilitysilent - mkdirp · mkdirp-path-component-is-fileerrorWhenA component of the path that should be a directory is actually an existing fileThrows
Error with code ENOTDIRRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOTDIR' to detect path conflicts. Same behavior as ensureDir() — a path component that exists as a file instead of a directory causes ENOTDIR from the underlying fs.mkdir({recursive: true}) call.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - mkdirs · mkdirs-permission-deniederrorWhenProcess lacks write or execute permission on a parent directory componentThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES' to handle permission errors. mkdirs() is identical to ensureDir() and mkdirp() — all call fs.mkdir({recursive: true}) via the same makeDir function. Directory creation failure will block all subsequent I/O at that path.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilitysilent - mkdirs · mkdirs-path-component-is-fileerrorWhenA component of the path that should be a directory is actually an existing fileThrows
Error with code ENOTDIRRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOTDIR' to detect path conflicts. mkdirs() is identical to ensureDir() — same underlying fs.mkdir({recursive: true}) behavior.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - createFile · createfile-permission-deniederrorWhenProcess lacks write permission on the target directory or execute permission on a parentThrows
Error with code EACCESRequired handlingCaller MUST wrap in try-catch. Check error.code === 'EACCES'. createFile() is the same underlying function as ensureFile() — both are exported as the same reference. Parent directory creation propagates EACCES from mkdir.mkdirs() unmodified. Common in init scripts that create log or pid files in permission-restricted paths.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilitysilent - createFile · createfile-path-component-is-fileerrorWhenA component of the path that should be a directory is actually an existing fileThrows
Error with code ENOTDIRRequired handlingCaller MUST wrap in try-catch. Check error.code === 'ENOTDIR'. The source explicitly calls fs.readdir(dir) to trigger ENOTDIR when the parent stat shows it is not a directory. createFile() is the same function as ensureFile() — identical ENOTDIR behavior.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[16]
Sources
Every postcondition cites at least one of these. Numbered to match the footnotes above.
- [1]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/readJson.md
- [2]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/copy.md
- [3]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/move.md
- [4]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/outputFile.md
- [5]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/output-file/index.js
- [6]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/writeJson.md
- [7]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/json/jsonfile.js
- [8]developer.mozilla.org/en-US/docshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
- [9]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir.md
- [10]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/mkdirs/make-dir.js
- [11]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/remove.md
- [12]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/remove/index.js
- [13]nodejs.org/api/fs.htmlhttps://nodejs.org/api/fs.html#fsrmpath-options-callback
- [14]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/json/output-json.js
- [15]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureFile.md
- [16]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/ensure/file.js
- [17]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/mkdirs/index.js
- [18]github.com/jprichardson/node-fs-extrahttps://github.com/jprichardson/node-fs-extra/blob/master/lib/ensure/index.js
Need a different package?
Request a profile