ArangoDB v3.2 reached End of Life (EOL) and is no longer supported.
This documentation is outdated. Please see the most recent version here: Try latest
const fs = require('fs')
The implementation tries to follow the CommonJS Filesystem/A/0 specification where possible.
Single File Directory Manipulation
checks if a file of any type or directory exists
Returns true if a file (of any type) or a directory exists at a given path. If the file is a broken symbolic link, returns false.
tests if path is a file
Returns true if the path points to a file.
tests if path is a directory
Returns true if the path points to a directory.
gets the size of a file
Returns the size of the file specified by path.
gets the last modification time of a file
Returns the last modification date of the specified file. The date is returned as a Unix timestamp (number of seconds elapsed since January 1 1970).
If you want to combine two paths you can use fs.pathSeparator instead of
The function returns the combination of the path and filename, e.g.
fs.join('folder', 'file.ext') would return
returns the name for a (new) temporary file
Returns the name for a new temporary file in directory directory. If createFile is true, an empty file will be created so no other process can create a file of the same name.
Note: The directory directory must exist.
returns the temporary directory
Returns the absolute path of the temporary directory
makes a given path absolute
Returns the given string if it is an absolute path, otherwise an absolute path to the same location is returned.
sets file permissions of specified files (non windows only)
Returns true on success.
returns the directory listing
The functions returns the names of all the files in a directory, in lexically sorted order. Throws an exception if the directory cannot be traversed (or path is not a directory).
Note: this means that list(“x”) of a directory containing “a” and “b” would return [“a”, “b”], not [“x/a”, “x/b”].
returns the directory tree
The function returns an array that starts with the given path, and all of
the paths relative to the given path, discovered by a depth first traversal
of every directory in any visited directory, reporting but not traversing
symbolic links to directories. The first path is always
"", the path
relative to itself.
creates a directory
Creates the directory specified by path.
creates a directory
Creates the directory hierarchy specified by path.
removes a file
Removes the file filename at the given path. Throws an exception if the path corresponds to anything that is not a file or a symbolic link. If “path” refers to a symbolic link, removes the symbolic link.
removes an empty directory
Removes a directory if it is empty. Throws an exception if the path is not an empty directory.
removes a directory
Removes a directory with all subelements. Throws an exception if the path is not a directory.
reads in a file
Reads in a file and returns the content as string. Please note that the file content must be encoded in UTF-8.
reads in a file as base64
Reads in a file and returns the content as string. The file content is Base64 encoded.
reads in a file
Reads in a file and returns its content in a Buffer object.
Reads the contents of the file specified in
encoding is specified,
the file contents will be returned as a string. Supported encodings are:
encoding is specified, the file contents will be returned in a Buffer
Writes the content into a file. Content can be a string or a Buffer object. If the file already exists, it is truncated.
This is an alias for
Writes the content into a file. Content can be a string or a Buffer object. If the file already exists, the content is appended at the end.
copies a directory structure
Copies source to destination. Exceptions will be thrown on:
- Failure to copy the file
- specifying a directory for destination when source is a file
- specifying a directory as source and destination
copies a file into a target file
Copies source to destination. If Destination is a directory, a file of the same name will be created in that directory, else the copy will get the specified filename.
renames a file
Moves source to destination. Failure to move the file, or specifying a directory for destination when source is a file will throw an exception. Likewise, specifying a directory as source and destination will fail.
unzips a file
fs.unzipFile(filename, outpath, skipPaths, overwrite, password)
Unzips the zip file specified by filename into the path specified by outpath. Overwrites any existing target files if overwrite is set to true.
Returns true if the file was unzipped successfully.
zips a file
fs.zipFile(filename, chdir, files, password)
Stores the files specified by files in the zip file filename. If the file filename already exists, an error is thrown. The list of input files files must be given as a list of absolute filenames. If chdir is not empty, the chdir prefix will be stripped from the filename in the zip file, so when it is unzipped filenames will be relative. Specifying a password is optional.
Returns true if the file was zipped successfully.