Synchronous version of fs.access(). This throws if any accessibility checks fail, and does nothing otherwise.
Asynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a buffer.
The synchronous version of fs.appendFile().
Asynchronous chmod(2).
Synchronous chmod(2).
Asynchronous chown(2).
Synchronous chown(2).
Asynchronous close(2).
Synchronous close(2).
Returns a new ReadStream object.
Be aware that, unlike the default value set for highWaterMark on a readable stream (16 kb), the stream returned by this method has a default value of 64 kb for the same parameter.
Returns a new WriteStream object.
Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false.
Synchronous version of fs.exists(). Returns true if the file exists, false otherwise.
Asynchronous fchmod(2).
Synchronous fchmod(2).
Asynchronous fchown(2).
Synchronous fchown(2).
Asynchronous fdatasync(2).
Synchronous fdatasync(2).
Asynchronous fstat(2).
Synchronous fstat(2).
Asynchronous fsync(2).
Synchronous fsync(2).
Asynchronous ftruncate(2).
If the file referred to by the file descriptor was larger than len bytes, only the first len bytes will be retained in the file.
If the file previously was shorter than len bytes, it is extended, and the extended part is filled with null bytes ('\0').
Synchronous ftruncate(2).
Change the file timestamps of a file referenced by the supplied file descriptor.
Synchronous version of fs.futimes().
Asynchronous lchmod(2).
Only available on Mac OS X.
Synchronous lchmod(2).
Asynchronous lchown(2).
Synchronous lchown(2).
Asynchronous link(2).
Asynchronous lstat(2). lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.
Asynchronous mkdir(2). mode defaults to 0o777.
Synchronous mkdir(2).
Creates a unique temporary directory.
Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
The created folder path is passed as a string to the callback's second parameter.
The synchronous version of fs.mkdtemp(). Returns the created folder path.
Asynchronous file open. See open(2). flags can be:
'r' - Open file for reading. An exception occurs if the file does not exist.
'r+' - Open file for reading and writing. An exception occurs if the file does not exist.
'rs+' - Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache.
This is primarily useful for opening files on NFS mounts as it allows you to skip the potentially stale local cache. It has a very real impact on I/O performance so don't use this flag unless you need it.
Note that this doesn't turn fs.open() into a synchronous blocking call. If that's what you want then you should be using fs.openSync()
'w' - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
'wx' - Like 'w' but fails if path exists.
'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
'wx+' - Like 'w+' but fails if path exists.
'a' - Open file for appending. The file is created if it does not exist.
'ax' - Like 'a' but fails if path exists.
'a+' - Open file for reading and appending. The file is created if it does not exist.
'ax+' - Like 'a+' but fails if path exists.
mode sets the file mode (permission and sticky bits), but only if the file was created. It defaults to 0666, readable and writable.
Synchronous version of fs.open().
Read data from the file specified by fd.
is the buffer that the data will be written to.
is the offset in the buffer to start writing at.
is an integer specifying the number of bytes to read.
is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.
Asynchronously reads the entire contents of a file.
Synchronous version of fs.readFile.
Synchronous version of fs.read().
Asynchronous readdir(3). Reads the contents of a directory.
Synchronous readdir(3). Returns an array of filenames excluding '.' and '..'.
Asynchronous readlink(2).
Synchronous readlink(2).
Asynchronous realpath(3). May use process.cwd to resolve relative paths.
Only paths that can be converted to UTF8 strings are supported.
Synchronous realpath(3). Returns the resolved path.
Only paths that can be converted to UTF8 strings are supported.
Asynchronous rename(2).
Asynchronous rmdir(2).
Synchronous rmdir(2).
Asynchronous stat(2).
In case of an error, the err.code will be one of Common System Errors.
Using fs.stat() to check for the existence of a file before calling fs.open(), fs.readFile() or fs.writeFile() is not recommended. Instead, user code should open/read/write the file directly and handle the error raised if the file is not available.
To check if a file exists without manipulating it afterwards, fs.access() is recommended.
Asynchronous symlink(2). The type argument is only available on Windows (ignored on other platforms). Note that Windows junction points require the destination path to be absolute. When using 'junction', the target argument will automatically be normalized to absolute path.
Asynchronous truncate(2).
Synchronous truncate(2).
Asynchronous unlink(2).
Synchronous unlink(2).
Stop watching for changes on filename. If listener is specified, only that particular listener is removed. Otherwise, all listeners are removed and you have effectively stopped watching filename.
Calling fs.unwatchFile() with a filename that is not being watched is a no-op, not an error.
Note: fs.watch() is more efficient than fs.watchFile() and fs.unwatchFile(). fs.watch() should be used instead of fs.watchFile() and fs.unwatchFile() when possible.
Change file timestamps of the file referenced by the supplied path.
Note: the arguments atime and mtime of the following related functions follow these rules:
Date.now() returns milliseconds, so it should be divided by 1000 before passing it in.
If the value is a numeric string like '123456789', the value will get converted to the corresponding number.
If the value is NaN or Infinity, the value will get converted to Date.now() / 1000.Synchronous version of fs.utimes().
Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher.
Please note the listener callback is attached to the 'change' event fired by fs.FSWatcher, but they are not the same thing.
Watch for changes on filename. The callback listener will be called each time the file is accessed.
Note: when an fs.watchFile operation results in an ENOENT error, it will invoke the listener once, with all the fields zeroed (or, for dates, the Unix Epoch). In Windows, blksize and blocks fields will be undefined, instead of zero. If the file is created later on, the listener will be called again, with the latest stat objects.
Note: fs.watch() is more efficient than fs.watchFile and fs.unwatchFile. fs.watch should be used instead of fs.watchFile and fs.unwatchFile when possible.
Write buffer to the file specified by fd.
offset and length determine the part of the buffer to be written.
position refers to the offset from the beginning of the file where this data should be written. If typeof position !== 'number', the data will be written at the current position. See pwrite(2).
Note that it is unsafe to use fs.write multiple times on the same file without waiting for the callback. For this scenario, fs.createWriteStream is strongly recommended.
On Linux, positional writes don't work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.
Asynchronously writes data to a file, replacing the file if it already exists.
Note that it is unsafe to use fs.writeFile multiple times on the same file without waiting for the callback. For this scenario, fs.createWriteStream is strongly recommended.
Note: If a file descriptor is specified as the file, it will not be closed automatically.
The synchronous version of fs.writeFile().
Generated using TypeDoc
Tests a user's permissions for the file or directory specified by
path. Themodeargument is an optional integer that specifies the accessibility checks to be performed. The following constants define the possible values ofmode. It is possible to create a mask consisting of the bitwise OR of two or more values.