{ "source": "doc/api/fs.md", "modules": [ { "textRaw": "File System", "name": "fs", "stability": 2, "stabilityText": "Stable", "desc": "

File I/O is provided by simple wrappers around standard POSIX functions. To\nuse this module do require('fs'). All the methods have asynchronous and\nsynchronous forms.

\n

The asynchronous form always takes a completion callback as its last argument.\nThe arguments passed to the completion callback depend on the method, but the\nfirst argument is always reserved for an exception. If the operation was\ncompleted successfully, then the first argument will be null or undefined.

\n

When using the synchronous form any exceptions are immediately thrown.\nYou can use try/catch to handle exceptions or allow them to bubble up.

\n

Here is an example of the asynchronous version:

\n
const fs = require('fs');\n\nfs.unlink('/tmp/hello', (err) => {\n  if (err) throw err;\n  console.log('successfully deleted /tmp/hello');\n});\n
\n

Here is the synchronous version:

\n
const fs = require('fs');\n\nfs.unlinkSync('/tmp/hello');\nconsole.log('successfully deleted /tmp/hello');\n
\n

With the asynchronous methods there is no guaranteed ordering. So the\nfollowing is prone to error:

\n
fs.rename('/tmp/hello', '/tmp/world', (err) => {\n  if (err) throw err;\n  console.log('renamed complete');\n});\nfs.stat('/tmp/world', (err, stats) => {\n  if (err) throw err;\n  console.log(`stats: ${JSON.stringify(stats)}`);\n});\n
\n

It could be that fs.stat is executed before fs.rename.\nThe correct way to do this is to chain the callbacks.

\n
fs.rename('/tmp/hello', '/tmp/world', (err) => {\n  if (err) throw err;\n  fs.stat('/tmp/world', (err, stats) => {\n    if (err) throw err;\n    console.log(`stats: ${JSON.stringify(stats)}`);\n  });\n});\n
\n

In busy processes, the programmer is strongly encouraged to use the\nasynchronous versions of these calls. The synchronous versions will block\nthe entire process until they complete--halting all connections.

\n

The relative path to a filename can be used. Remember, however, that this path\nwill be relative to process.cwd().

\n

Most fs functions let you omit the callback argument. If you do, a default\ncallback is used that rethrows errors. To get a trace to the original call\nsite, set the NODE_DEBUG environment variable:

\n
$ cat script.js\nfunction bad() {\n  require('fs').readFile('/');\n}\nbad();\n\n$ env NODE_DEBUG=fs node script.js\nfs.js:88\n        throw backtrace;\n        ^\nError: EISDIR: illegal operation on a directory, read\n    <stack trace.>\n
\n", "modules": [ { "textRaw": "Buffer API", "name": "buffer_api", "meta": { "added": [ "v6.0.0" ], "changes": [] }, "desc": "

fs functions support passing and receiving paths as both strings\nand Buffers. The latter is intended to make it possible to work with\nfilesystems that allow for non-UTF-8 filenames. For most typical\nuses, working with paths as Buffers will be unnecessary, as the string\nAPI converts to and from UTF-8 automatically.

\n

Note that on certain file systems (such as NTFS and HFS+) filenames\nwill always be encoded as UTF-8. On such file systems, passing\nnon-UTF-8 encoded Buffers to fs functions will not work as expected.

\n", "type": "module", "displayName": "Buffer API" }, { "textRaw": "FS Constants", "name": "fs_constants", "desc": "

The following constants are exported by fs.constants. Note: Not every\nconstant will be available on every operating system.

\n", "modules": [ { "textRaw": "File Access Constants", "name": "file_access_constants", "desc": "

The following constants are meant for use with fs.access().

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
ConstantDescription
F_OKFlag indicating that the file is visible to the calling process.
R_OKFlag indicating that the file can be read by the calling process.
W_OKFlag indicating that the file can be written by the calling\n process.
X_OKFlag indicating that the file can be executed by the calling\n process.
\n\n", "type": "module", "displayName": "File Access Constants" }, { "textRaw": "File Open Constants", "name": "file_open_constants", "desc": "

The following constants are meant for use with fs.open().

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
ConstantDescription
O_RDONLYFlag indicating to open a file for read-only access.
O_WRONLYFlag indicating to open a file for write-only access.
O_RDWRFlag indicating to open a file for read-write access.
O_CREATFlag indicating to create the file if it does not already exist.
O_EXCLFlag indicating that opening a file should fail if the\n O_CREAT flag is set and the file already exists.
O_NOCTTYFlag indicating that if path identifies a terminal device, opening the\n path shall not cause that terminal to become the controlling terminal for\n the process (if the process does not already have one).
O_TRUNCFlag indicating that if the file exists and is a regular file, and the\n file is opened successfully for write access, its length shall be truncated\n to zero.
O_APPENDFlag indicating that data will be appended to the end of the file.
O_DIRECTORYFlag indicating that the open should fail if the path is not a\n directory.
O_NOATIMEFlag indicating reading accesses to the file system will no longer\n result in an update to the atime information associated with the file.\n This flag is available on Linux operating systems only.
O_NOFOLLOWFlag indicating that the open should fail if the path is a symbolic\n link.
O_SYNCFlag indicating that the file is opened for synchronous I/O.
O_SYMLINKFlag indicating to open the symbolic link itself rather than the\n resource it is pointing to.
O_DIRECTWhen set, an attempt will be made to minimize caching effects of file\n I/O.
O_NONBLOCKFlag indicating to open the file in nonblocking mode when possible.
\n\n", "type": "module", "displayName": "File Open Constants" }, { "textRaw": "File Type Constants", "name": "file_type_constants", "desc": "

The following constants are meant for use with the fs.Stats object's\nmode property for determining a file's type.

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
ConstantDescription
S_IFMTBit mask used to extract the file type code.
S_IFREGFile type constant for a regular file.
S_IFDIRFile type constant for a directory.
S_IFCHRFile type constant for a character-oriented device file.
S_IFBLKFile type constant for a block-oriented device file.
S_IFIFOFile type constant for a FIFO/pipe.
S_IFLNKFile type constant for a symbolic link.
S_IFSOCKFile type constant for a socket.
\n\n", "type": "module", "displayName": "File Type Constants" }, { "textRaw": "File Mode Constants", "name": "file_mode_constants", "desc": "

The following constants are meant for use with the fs.Stats object's\nmode property for determining the access permissions for a file.

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
ConstantDescription
S_IRWXUFile mode indicating readable, writable and executable by owner.
S_IRUSRFile mode indicating readable by owner.
S_IWUSRFile mode indicating writable by owner.
S_IXUSRFile mode indicating executable by owner.
S_IRWXGFile mode indicating readable, writable and executable by group.
S_IRGRPFile mode indicating readable by group.
S_IWGRPFile mode indicating writable by group.
S_IXGRPFile mode indicating executable by group.
S_IRWXOFile mode indicating readable, writable and executable by others.
S_IROTHFile mode indicating readable by others.
S_IWOTHFile mode indicating writable by others.
S_IXOTHFile mode indicating executable by others.
\n\n", "type": "module", "displayName": "File Mode Constants" } ], "type": "module", "displayName": "FS Constants" } ], "classes": [ { "textRaw": "Class: fs.FSWatcher", "type": "class", "name": "fs.FSWatcher", "meta": { "added": [ "v0.5.8" ], "changes": [] }, "desc": "

Objects returned from fs.watch() are of this type.

\n

The listener callback provided to fs.watch() receives the returned FSWatcher's\nchange events.

\n

The object itself emits these events:

\n", "events": [ { "textRaw": "Event: 'change'", "type": "event", "name": "change", "meta": { "added": [ "v0.5.8" ], "changes": [] }, "params": [], "desc": "

Emitted when something changes in a watched directory or file.\nSee more details in fs.watch().

\n

The filename argument may not be provided depending on operating system\nsupport. If filename is provided, it will be provided as a Buffer if\nfs.watch() is called with its encoding option set to 'buffer', otherwise\nfilename will be a string.

\n
// Example when handled through fs.watch listener\nfs.watch('./tmp', {encoding: 'buffer'}, (eventType, filename) => {\n  if (filename)\n    console.log(filename);\n    // Prints: <Buffer ...>\n});\n
\n" }, { "textRaw": "Event: 'error'", "type": "event", "name": "error", "meta": { "added": [ "v0.5.8" ], "changes": [] }, "params": [], "desc": "

Emitted when an error occurs.

\n" } ], "methods": [ { "textRaw": "watcher.close()", "type": "method", "name": "close", "meta": { "added": [ "v0.5.8" ], "changes": [] }, "desc": "

Stop watching for changes on the given fs.FSWatcher.

\n", "signatures": [ { "params": [] } ] } ] }, { "textRaw": "Class: fs.ReadStream", "type": "class", "name": "fs.ReadStream", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "desc": "

ReadStream is a Readable Stream.

\n", "events": [ { "textRaw": "Event: 'close'", "type": "event", "name": "close", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "desc": "

Emitted when the ReadStream's underlying file descriptor has been closed\nusing the fs.close() method.

\n", "params": [] }, { "textRaw": "Event: 'open'", "type": "event", "name": "open", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "params": [], "desc": "

Emitted when the ReadStream's file is opened.

\n" } ], "properties": [ { "textRaw": "readStream.bytesRead", "name": "bytesRead", "meta": { "added": [ "6.4.0" ], "changes": [] }, "desc": "

The number of bytes read so far.

\n" }, { "textRaw": "readStream.path", "name": "path", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "desc": "

The path to the file the stream is reading from as specified in the first\nargument to fs.createReadStream(). If path is passed as a string, then\nreadStream.path will be a string. If path is passed as a Buffer, then\nreadStream.path will be a Buffer.

\n" } ] }, { "textRaw": "Class: fs.Stats", "type": "class", "name": "fs.Stats", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "desc": "

Objects returned from fs.stat(), fs.lstat() and fs.fstat() and their\nsynchronous counterparts are of this type.

\n\n

For a regular file util.inspect(stats) would return a string very\nsimilar to this:

\n
{\n  dev: 2114,\n  ino: 48064969,\n  mode: 33188,\n  nlink: 1,\n  uid: 85,\n  gid: 100,\n  rdev: 0,\n  size: 527,\n  blksize: 4096,\n  blocks: 8,\n  atime: Mon, 10 Oct 2011 23:24:11 GMT,\n  mtime: Mon, 10 Oct 2011 23:24:11 GMT,\n  ctime: Mon, 10 Oct 2011 23:24:11 GMT,\n  birthtime: Mon, 10 Oct 2011 23:24:11 GMT\n}\n
\n

Please note that atime, mtime, birthtime, and ctime are\ninstances of Date object and to compare the values of\nthese objects you should use appropriate methods. For most general\nuses getTime() will return the number of\nmilliseconds elapsed since 1 January 1970 00:00:00 UTC and this\ninteger should be sufficient for any comparison, however there are\nadditional methods which can be used for displaying fuzzy information.\nMore details can be found in the MDN JavaScript Reference\npage.

\n", "modules": [ { "textRaw": "Stat Time Values", "name": "stat_time_values", "desc": "

The times in the stat object have the following semantics:

\n\n

Prior to Node v0.12, the ctime held the birthtime on Windows\nsystems. Note that as of v0.12, ctime is not "creation time", and\non Unix systems, it never was.

\n", "type": "module", "displayName": "Stat Time Values" } ] }, { "textRaw": "Class: fs.WriteStream", "type": "class", "name": "fs.WriteStream", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "desc": "

WriteStream is a Writable Stream.

\n", "events": [ { "textRaw": "Event: 'close'", "type": "event", "name": "close", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "desc": "

Emitted when the WriteStream's underlying file descriptor has been closed\nusing the fs.close() method.

\n", "params": [] }, { "textRaw": "Event: 'open'", "type": "event", "name": "open", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "params": [], "desc": "

Emitted when the WriteStream's file is opened.

\n" } ], "properties": [ { "textRaw": "writeStream.bytesWritten", "name": "bytesWritten", "meta": { "added": [ "v0.4.7" ], "changes": [] }, "desc": "

The number of bytes written so far. Does not include data that is still queued\nfor writing.

\n" }, { "textRaw": "writeStream.path", "name": "path", "meta": { "added": [ "v0.1.93" ], "changes": [] }, "desc": "

The path to the file the stream is writing to as specified in the first\nargument to fs.createWriteStream(). If path is passed as a string, then\nwriteStream.path will be a string. If path is passed as a Buffer, then\nwriteStream.path will be a Buffer.

\n" } ] } ], "methods": [ { "textRaw": "fs.access(path[, mode], callback)", "type": "method", "name": "access", "meta": { "added": [ "v0.11.15" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "mode", "optional": true }, { "name": "callback" } ] } ], "desc": "

Tests a user's permissions for the file or directory specified by path.\nThe mode argument is an optional integer that specifies the accessibility\nchecks to be performed. The following constants define the possible values of\nmode. It is possible to create a mask consisting of the bitwise OR of two or\nmore values.

\n\n

The final argument, callback, is a callback function that is invoked with\na possible error argument. If any of the accessibility checks fail, the error\nargument will be populated. The following example checks if the file\n/etc/passwd can be read and written by the current process.

\n
fs.access('/etc/passwd', fs.constants.R_OK | fs.constants.W_OK, (err) => {\n  console.log(err ? 'no access!' : 'can read/write');\n});\n
\n

Using fs.access() to check for the accessibility of a file before calling\nfs.open(), fs.readFile() or fs.writeFile() is not recommended. Doing\nso introduces a race condition, since other processes may change the file's\nstate between the two calls. Instead, user code should open/read/write the\nfile directly and handle the error raised if the file is not accessible.

\n

For example:

\n

write (NOT RECOMMENDED)

\n
fs.access('myfile', (err) => {\n  if (!err) {\n    console.error('myfile already exists');\n    return;\n  }\n\n  fs.open('myfile', 'wx', (err, fd) => {\n    if (err) throw err;\n    writeMyData(fd);\n  });\n});\n
\n

write (RECOMMENDED)

\n
fs.open('myfile', 'wx', (err, fd) => {\n  if (err) {\n    if (err.code === "EEXIST") {\n      console.error('myfile already exists');\n      return;\n    } else {\n      throw err;\n    }\n  }\n\n  writeMyData(fd);\n});\n
\n

read (NOT RECOMMENDED)

\n
fs.access('myfile', (err) => {\n  if (err) {\n    if (err.code === "ENOENT") {\n      console.error('myfile does not exist');\n      return;\n    } else {\n      throw err;\n    }\n  }\n\n  fs.open('myfile', 'r', (err, fd) => {\n    if (err) throw err;\n    readMyData(fd);\n  });\n});\n
\n

read (RECOMMENDED)

\n
fs.open('myfile', 'r', (err, fd) => {\n  if (err) {\n    if (err.code === "ENOENT") {\n      console.error('myfile does not exist');\n      return;\n    } else {\n      throw err;\n    }\n  }\n\n  readMyData(fd);\n});\n
\n

The "not recommended" examples above check for accessibility and then use the\nfile; the "recommended" examples are better because they use the file directly\nand handle the error, if any.

\n

In general, check for the accessibility of a file only if the file won’t be\nused directly, for example when its accessibility is a signal from another\nprocess.

\n" }, { "textRaw": "fs.accessSync(path[, mode])", "type": "method", "name": "accessSync", "meta": { "added": [ "v0.11.15" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "mode", "optional": true } ] } ], "desc": "

Synchronous version of fs.access(). This throws if any accessibility\nchecks fail, and does nothing otherwise.

\n" }, { "textRaw": "fs.appendFile(file, data[, options], callback)", "type": "method", "name": "appendFile", "meta": { "added": [ "v0.6.7" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7831", "description": "The passed `options` object will never be modified." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/3163", "description": "The `file` parameter can be a file descriptor now." } ] }, "signatures": [ { "params": [ { "textRaw": "`file` {String | Buffer | Number} filename or file descriptor ", "name": "file", "type": "String | Buffer | Number", "desc": "filename or file descriptor" }, { "textRaw": "`data` {String | Buffer} ", "name": "data", "type": "String | Buffer" }, { "textRaw": "`options` {Object | String} ", "options": [ { "textRaw": "`encoding` {String | Null} default = `'utf8'` ", "name": "encoding", "type": "String | Null", "desc": "default = `'utf8'`" }, { "textRaw": "`mode` {Integer} default = `0o666` ", "name": "mode", "type": "Integer", "desc": "default = `0o666`" }, { "textRaw": "`flag` {String} default = `'a'` ", "name": "flag", "type": "String", "desc": "default = `'a'`" } ], "name": "options", "type": "Object | String", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "file" }, { "name": "data" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronously append data to a file, creating the file if it does not yet exist.\ndata can be a string or a buffer.

\n

Example:

\n
fs.appendFile('message.txt', 'data to append', (err) => {\n  if (err) throw err;\n  console.log('The "data to append" was appended to file!');\n});\n
\n

If options is a string, then it specifies the encoding. Example:

\n
fs.appendFile('message.txt', 'data to append', 'utf8', callback);\n
\n

Any specified file descriptor has to have been opened for appending.

\n

Note: If a file descriptor is specified as the file, it will not be closed\nautomatically.

\n" }, { "textRaw": "fs.appendFileSync(file, data[, options])", "type": "method", "name": "appendFileSync", "meta": { "added": [ "v0.6.7" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7831", "description": "The passed `options` object will never be modified." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/3163", "description": "The `file` parameter can be a file descriptor now." } ] }, "signatures": [ { "params": [ { "textRaw": "`file` {String | Buffer | Number} filename or file descriptor ", "name": "file", "type": "String | Buffer | Number", "desc": "filename or file descriptor" }, { "textRaw": "`data` {String | Buffer} ", "name": "data", "type": "String | Buffer" }, { "textRaw": "`options` {Object | String} ", "options": [ { "textRaw": "`encoding` {String | Null} default = `'utf8'` ", "name": "encoding", "type": "String | Null", "desc": "default = `'utf8'`" }, { "textRaw": "`mode` {Integer} default = `0o666` ", "name": "mode", "type": "Integer", "desc": "default = `0o666`" }, { "textRaw": "`flag` {String} default = `'a'` ", "name": "flag", "type": "String", "desc": "default = `'a'`" } ], "name": "options", "type": "Object | String", "optional": true } ] }, { "params": [ { "name": "file" }, { "name": "data" }, { "name": "options", "optional": true } ] } ], "desc": "

The synchronous version of fs.appendFile(). Returns undefined.

\n" }, { "textRaw": "fs.chmod(path, mode, callback)", "type": "method", "name": "chmod", "meta": { "added": [ "v0.1.30" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "mode" }, { "name": "callback" } ] } ], "desc": "

Asynchronous chmod(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.chmodSync(path, mode)", "type": "method", "name": "chmodSync", "meta": { "added": [ "v0.6.7" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" } ] }, { "params": [ { "name": "path" }, { "name": "mode" } ] } ], "desc": "

Synchronous chmod(2). Returns undefined.

\n" }, { "textRaw": "fs.chown(path, uid, gid, callback)", "type": "method", "name": "chown", "meta": { "added": [ "v0.1.97" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`uid` {Integer} ", "name": "uid", "type": "Integer" }, { "textRaw": "`gid` {Integer} ", "name": "gid", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "uid" }, { "name": "gid" }, { "name": "callback" } ] } ], "desc": "

Asynchronous chown(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.chownSync(path, uid, gid)", "type": "method", "name": "chownSync", "meta": { "added": [ "v0.1.97" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`uid` {Integer} ", "name": "uid", "type": "Integer" }, { "textRaw": "`gid` {Integer} ", "name": "gid", "type": "Integer" } ] }, { "params": [ { "name": "path" }, { "name": "uid" }, { "name": "gid" } ] } ], "desc": "

Synchronous chown(2). Returns undefined.

\n" }, { "textRaw": "fs.close(fd, callback)", "type": "method", "name": "close", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "callback" } ] } ], "desc": "

Asynchronous close(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.closeSync(fd)", "type": "method", "name": "closeSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" } ] }, { "params": [ { "name": "fd" } ] } ], "desc": "

Synchronous close(2). Returns undefined.

\n" }, { "textRaw": "fs.createReadStream(path[, options])", "type": "method", "name": "createReadStream", "meta": { "added": [ "v0.1.31" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7831", "description": "The passed `options` object will never be modified." }, { "version": "v2.3.0", "pr-url": "https://github.com/nodejs/node/pull/1845", "description": "The passed `options` object can be a string now." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`flags` {String} ", "name": "flags", "type": "String" }, { "textRaw": "`encoding` {String} ", "name": "encoding", "type": "String" }, { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" }, { "textRaw": "`autoClose` {Boolean} ", "name": "autoClose", "type": "Boolean" }, { "textRaw": "`start` {Integer} ", "name": "start", "type": "Integer" }, { "textRaw": "`end` {Integer} ", "name": "end", "type": "Integer" } ], "name": "options", "type": "String | Object", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true } ] } ], "desc": "

Returns a new ReadStream object. (See Readable Stream).

\n

Be aware that, unlike the default value set for highWaterMark on a\nreadable stream (16 kb), the stream returned by this method has a\ndefault value of 64 kb for the same parameter.

\n

options is an object or string with the following defaults:

\n
{\n  flags: 'r',\n  encoding: null,\n  fd: null,\n  mode: 0o666,\n  autoClose: true\n}\n
\n

options can include start and end values to read a range of bytes from\nthe file instead of the entire file. Both start and end are inclusive and\nstart counting at 0. If fd is specified and start is omitted or undefined,\nfs.createReadStream() reads sequentially from the current file position.\nThe encoding can be any one of those accepted by Buffer.

\n

If fd is specified, ReadStream will ignore the path argument and will use\nthe specified file descriptor. This means that no 'open' event will be\nemitted. Note that fd should be blocking; non-blocking fds should be passed\nto net.Socket.

\n

If autoClose is false, then the file descriptor won't be closed, even if\nthere's an error. It is your responsibility to close it and make sure\nthere's no file descriptor leak. If autoClose is set to true (default\nbehavior), on error or end the file descriptor will be closed\nautomatically.

\n

mode sets the file mode (permission and sticky bits), but only if the\nfile was created.

\n

An example to read the last 10 bytes of a file which is 100 bytes long:

\n
fs.createReadStream('sample.txt', {start: 90, end: 99});\n
\n

If options is a string, then it specifies the encoding.

\n" }, { "textRaw": "fs.createWriteStream(path[, options])", "type": "method", "name": "createWriteStream", "meta": { "added": [ "v0.1.31" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7831", "description": "The passed `options` object will never be modified." }, { "version": "v5.5.0", "pr-url": "https://github.com/nodejs/node/pull/3679", "description": "The `autoClose` option is supported now." }, { "version": "v2.3.0", "pr-url": "https://github.com/nodejs/node/pull/1845", "description": "The passed `options` object can be a string now." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`flags` {String} ", "name": "flags", "type": "String" }, { "textRaw": "`defaultEncoding` {String} ", "name": "defaultEncoding", "type": "String" }, { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" }, { "textRaw": "`autoClose` {Boolean} ", "name": "autoClose", "type": "Boolean" }, { "textRaw": "`start` {Integer} ", "name": "start", "type": "Integer" } ], "name": "options", "type": "String | Object", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true } ] } ], "desc": "

Returns a new WriteStream object. (See Writable Stream).

\n

options is an object or string with the following defaults:

\n
{\n  flags: 'w',\n  defaultEncoding: 'utf8',\n  fd: null,\n  mode: 0o666,\n  autoClose: true\n}\n
\n

options may also include a start option to allow writing data at\nsome position past the beginning of the file. Modifying a file rather\nthan replacing it may require a flags mode of r+ rather than the\ndefault mode w. The defaultEncoding can be any one of those accepted by\nBuffer.

\n

If autoClose is set to true (default behavior) on error or end\nthe file descriptor will be closed automatically. If autoClose is false,\nthen the file descriptor won't be closed, even if there's an error.\nIt is your responsibility to close it and make sure\nthere's no file descriptor leak.

\n

Like ReadStream, if fd is specified, WriteStream will ignore the\npath argument and will use the specified file descriptor. This means that no\n'open' event will be emitted. Note that fd should be blocking; non-blocking\nfds should be passed to net.Socket.

\n

If options is a string, then it specifies the encoding.

\n" }, { "textRaw": "fs.exists(path, callback)", "type": "method", "name": "exists", "meta": { "added": [ "v0.0.2" ], "deprecated": [ "v1.0.0" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`fs.stat()`][] or [`fs.access()`][] instead.", "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "callback" } ] } ], "desc": "

Test whether or not the given path exists by checking with the file system.\nThen call the callback argument with either true or false. Example:

\n
fs.exists('/etc/passwd', (exists) => {\n  console.log(exists ? 'it\\'s there' : 'no passwd!');\n});\n
\n

Note that the parameter to this callback is not consistent with other\nNode.js callbacks. Normally, the first parameter to a Node.js callback is\nan err parameter, optionally followed by other parameters. The\nfs.exists() callback has only one boolean parameter. This is one reason\nfs.access() is recommended instead of fs.exists().

\n

Using fs.exists() to check for the existence of a file before calling\nfs.open(), fs.readFile() or fs.writeFile() is not recommended. Doing\nso introduces a race condition, since other processes may change the file's\nstate between the two calls. Instead, user code should open/read/write the\nfile directly and handle the error raised if the file does not exist.

\n

For example:

\n

write (NOT RECOMMENDED)

\n
fs.exists('myfile', (exists) => {\n  if (exists) {\n    console.error('myfile already exists');\n  } else {\n    fs.open('myfile', 'wx', (err, fd) => {\n      if (err) throw err;\n      writeMyData(fd);\n    });\n  }\n});\n
\n

write (RECOMMENDED)

\n
fs.open('myfile', 'wx', (err, fd) => {\n  if (err) {\n    if (err.code === "EEXIST") {\n      console.error('myfile already exists');\n      return;\n    } else {\n      throw err;\n    }\n  }\n  writeMyData(fd);\n});\n
\n

read (NOT RECOMMENDED)

\n
fs.exists('myfile', (exists) => {\n  if (exists) {\n    fs.open('myfile', 'r', (err, fd) => {\n      readMyData(fd);\n    });\n  } else {\n    console.error('myfile does not exist');\n  }\n});\n
\n

read (RECOMMENDED)

\n
fs.open('myfile', 'r', (err, fd) => {\n  if (err) {\n    if (err.code === "ENOENT") {\n      console.error('myfile does not exist');\n      return;\n    } else {\n      throw err;\n    }\n  } else {\n    readMyData(fd);\n  }\n});\n
\n

The "not recommended" examples above check for existence and then use the\nfile; the "recommended" examples are better because they use the file directly\nand handle the error, if any.

\n

In general, check for the existence of a file only if the file won’t be\nused directly, for example when its existence is a signal from another\nprocess.

\n" }, { "textRaw": "fs.existsSync(path)", "type": "method", "name": "existsSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" } ] }, { "params": [ { "name": "path" } ] } ], "desc": "

Synchronous version of fs.exists().\nReturns true if the file exists, false otherwise.

\n

Note that fs.exists() is deprecated, but fs.existsSync() is not.\n(The callback parameter to fs.exists() accepts parameters that are\ninconsistent with other Node.js callbacks. fs.existsSync() does not use\na callback.)

\n" }, { "textRaw": "fs.fchmod(fd, mode, callback)", "type": "method", "name": "fchmod", "meta": { "added": [ "v0.4.7" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "mode" }, { "name": "callback" } ] } ], "desc": "

Asynchronous fchmod(2). No arguments other than a possible exception\nare given to the completion callback.

\n" }, { "textRaw": "fs.fchmodSync(fd, mode)", "type": "method", "name": "fchmodSync", "meta": { "added": [ "v0.4.7" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" } ] }, { "params": [ { "name": "fd" }, { "name": "mode" } ] } ], "desc": "

Synchronous fchmod(2). Returns undefined.

\n" }, { "textRaw": "fs.fchown(fd, uid, gid, callback)", "type": "method", "name": "fchown", "meta": { "added": [ "v0.4.7" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`uid` {Integer} ", "name": "uid", "type": "Integer" }, { "textRaw": "`gid` {Integer} ", "name": "gid", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "uid" }, { "name": "gid" }, { "name": "callback" } ] } ], "desc": "

Asynchronous fchown(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.fchownSync(fd, uid, gid)", "type": "method", "name": "fchownSync", "meta": { "added": [ "v0.4.7" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`uid` {Integer} ", "name": "uid", "type": "Integer" }, { "textRaw": "`gid` {Integer} ", "name": "gid", "type": "Integer" } ] }, { "params": [ { "name": "fd" }, { "name": "uid" }, { "name": "gid" } ] } ], "desc": "

Synchronous fchown(2). Returns undefined.

\n" }, { "textRaw": "fs.fdatasync(fd, callback)", "type": "method", "name": "fdatasync", "meta": { "added": [ "v0.1.96" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "callback" } ] } ], "desc": "

Asynchronous fdatasync(2). No arguments other than a possible exception are\ngiven to the completion callback.

\n" }, { "textRaw": "fs.fdatasyncSync(fd)", "type": "method", "name": "fdatasyncSync", "meta": { "added": [ "v0.1.96" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" } ] }, { "params": [ { "name": "fd" } ] } ], "desc": "

Synchronous fdatasync(2). Returns undefined.

\n" }, { "textRaw": "fs.fstat(fd, callback)", "type": "method", "name": "fstat", "meta": { "added": [ "v0.1.95" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "callback" } ] } ], "desc": "

Asynchronous fstat(2). The callback gets two arguments (err, stats) where\nstats is an fs.Stats object. fstat() is identical to stat(),\nexcept that the file to be stat-ed is specified by the file descriptor fd.

\n" }, { "textRaw": "fs.fstatSync(fd)", "type": "method", "name": "fstatSync", "meta": { "added": [ "v0.1.95" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" } ] }, { "params": [ { "name": "fd" } ] } ], "desc": "

Synchronous fstat(2). Returns an instance of fs.Stats.

\n" }, { "textRaw": "fs.fsync(fd, callback)", "type": "method", "name": "fsync", "meta": { "added": [ "v0.1.96" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "callback" } ] } ], "desc": "

Asynchronous fsync(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.fsyncSync(fd)", "type": "method", "name": "fsyncSync", "meta": { "added": [ "v0.1.96" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" } ] }, { "params": [ { "name": "fd" } ] } ], "desc": "

Synchronous fsync(2). Returns undefined.

\n" }, { "textRaw": "fs.ftruncate(fd, len, callback)", "type": "method", "name": "ftruncate", "meta": { "added": [ "v0.8.6" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`len` {Integer} default = `0` ", "name": "len", "type": "Integer", "desc": "default = `0`" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "len" }, { "name": "callback" } ] } ], "desc": "

Asynchronous ftruncate(2). No arguments other than a possible exception are\ngiven to the completion callback.

\n

If the file referred to by the file descriptor was larger than len bytes, only\nthe first len bytes will be retained in the file.

\n

For example, the following program retains only the first four bytes of the file

\n
console.log(fs.readFileSync('temp.txt', 'utf8'));\n// Prints: Node.js\n\n// get the file descriptor of the file to be truncated\nconst fd = fs.openSync('temp.txt', 'r+');\n\n// truncate the file to first four bytes\nfs.ftruncate(fd, 4, (err) => {\n  assert.ifError(err);\n  console.log(fs.readFileSync('temp.txt', 'utf8'));\n});\n// Prints: Node\n
\n

If the file previously was shorter than len bytes, it is extended, and the\nextended part is filled with null bytes ('\\0'). For example,

\n
console.log(fs.readFileSync('temp.txt', 'utf-8'));\n// Prints: Node.js\n\n// get the file descriptor of the file to be truncated\nconst fd = fs.openSync('temp.txt', 'r+');\n\n// truncate the file to 10 bytes, whereas the actual size is 7 bytes\nfs.ftruncate(fd, 10, (err) => {\n  assert.ifError(!err);\n  console.log(fs.readFileSync('temp.txt'));\n});\n// Prints: <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>\n// ('Node.js\\0\\0\\0' in UTF8)\n
\n

The last three bytes are null bytes ('\\0'), to compensate the over-truncation.

\n" }, { "textRaw": "fs.ftruncateSync(fd, len)", "type": "method", "name": "ftruncateSync", "meta": { "added": [ "v0.8.6" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`len` {Integer} default = `0` ", "name": "len", "type": "Integer", "desc": "default = `0`" } ] }, { "params": [ { "name": "fd" }, { "name": "len" } ] } ], "desc": "

Synchronous ftruncate(2). Returns undefined.

\n" }, { "textRaw": "fs.futimes(fd, atime, mtime, callback)", "type": "method", "name": "futimes", "meta": { "added": [ "v0.4.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v4.1.0", "pr-url": "https://github.com/nodejs/node/pull/2387", "description": "Numeric strings, `NaN` and `Infinity` are now allowed time specifiers." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`atime` {Integer} ", "name": "atime", "type": "Integer" }, { "textRaw": "`mtime` {Integer} ", "name": "mtime", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "atime" }, { "name": "mtime" }, { "name": "callback" } ] } ], "desc": "

Change the file timestamps of a file referenced by the supplied file\ndescriptor.

\n" }, { "textRaw": "fs.futimesSync(fd, atime, mtime)", "type": "method", "name": "futimesSync", "meta": { "added": [ "v0.4.2" ], "changes": [ { "version": "v4.1.0", "pr-url": "https://github.com/nodejs/node/pull/2387", "description": "Numeric strings, `NaN` and `Infinity` are now allowed time specifiers." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`atime` {Integer} ", "name": "atime", "type": "Integer" }, { "textRaw": "`mtime` {Integer} ", "name": "mtime", "type": "Integer" } ] }, { "params": [ { "name": "fd" }, { "name": "atime" }, { "name": "mtime" } ] } ], "desc": "

Synchronous version of fs.futimes(). Returns undefined.

\n" }, { "textRaw": "fs.lchmod(path, mode, callback)", "type": "method", "name": "lchmod", "meta": { "deprecated": [ "v0.4.7" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "mode" }, { "name": "callback" } ] } ], "desc": "

Asynchronous lchmod(2). No arguments other than a possible exception\nare given to the completion callback.

\n

Only available on Mac OS X.

\n" }, { "textRaw": "fs.lchmodSync(path, mode)", "type": "method", "name": "lchmodSync", "meta": { "deprecated": [ "v0.4.7" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer" } ] }, { "params": [ { "name": "path" }, { "name": "mode" } ] } ], "desc": "

Synchronous lchmod(2). Returns undefined.

\n" }, { "textRaw": "fs.lchown(path, uid, gid, callback)", "type": "method", "name": "lchown", "meta": { "deprecated": [ "v0.4.7" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`uid` {Integer} ", "name": "uid", "type": "Integer" }, { "textRaw": "`gid` {Integer} ", "name": "gid", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "uid" }, { "name": "gid" }, { "name": "callback" } ] } ], "desc": "

Asynchronous lchown(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.lchownSync(path, uid, gid)", "type": "method", "name": "lchownSync", "meta": { "deprecated": [ "v0.4.7" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`uid` {Integer} ", "name": "uid", "type": "Integer" }, { "textRaw": "`gid` {Integer} ", "name": "gid", "type": "Integer" } ] }, { "params": [ { "name": "path" }, { "name": "uid" }, { "name": "gid" } ] } ], "desc": "

Synchronous lchown(2). Returns undefined.

\n" }, { "textRaw": "fs.link(existingPath, newPath, callback)", "type": "method", "name": "link", "meta": { "added": [ "v0.1.31" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`existingPath` {String | Buffer} ", "name": "existingPath", "type": "String | Buffer" }, { "textRaw": "`newPath` {String | Buffer} ", "name": "newPath", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "existingPath" }, { "name": "newPath" }, { "name": "callback" } ] } ], "desc": "

Asynchronous link(2). No arguments other than a possible exception are given to\nthe completion callback.

\n" }, { "textRaw": "fs.linkSync(existingPath, newPath)", "type": "method", "name": "linkSync", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`existingPath` {String | Buffer} ", "name": "existingPath", "type": "String | Buffer" }, { "textRaw": "`newPath` {String | Buffer} ", "name": "newPath", "type": "String | Buffer" } ] }, { "params": [ { "name": "existingPath" }, { "name": "newPath" } ] } ], "desc": "

Synchronous link(2). Returns undefined.

\n" }, { "textRaw": "fs.lstat(path, callback)", "type": "method", "name": "lstat", "meta": { "added": [ "v0.1.30" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "callback" } ] } ], "desc": "

Asynchronous lstat(2). The callback gets two arguments (err, stats) where\nstats is a fs.Stats object. lstat() is identical to stat(),\nexcept that if path is a symbolic link, then the link itself is stat-ed,\nnot the file that it refers to.

\n" }, { "textRaw": "fs.lstatSync(path)", "type": "method", "name": "lstatSync", "meta": { "added": [ "v0.1.30" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" } ] }, { "params": [ { "name": "path" } ] } ], "desc": "

Synchronous lstat(2). Returns an instance of fs.Stats.

\n" }, { "textRaw": "fs.mkdir(path[, mode], callback)", "type": "method", "name": "mkdir", "meta": { "added": [ "v0.1.8" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "mode", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronous mkdir(2). No arguments other than a possible exception are given\nto the completion callback. mode defaults to 0o777.

\n" }, { "textRaw": "fs.mkdirSync(path[, mode])", "type": "method", "name": "mkdirSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "mode", "optional": true } ] } ], "desc": "

Synchronous mkdir(2). Returns undefined.

\n" }, { "textRaw": "fs.mkdtemp(prefix[, options], callback)", "type": "method", "name": "mkdtemp", "meta": { "added": [ "v5.10.0" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v6.2.1", "pr-url": "https://github.com/nodejs/node/pull/6828", "description": "The `callback` parameter is optional now." } ] }, "signatures": [ { "params": [ { "textRaw": "`prefix` {String} ", "name": "prefix", "type": "String" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "prefix" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Creates a unique temporary directory.

\n

Generates six random characters to be appended behind a required\nprefix to create a unique temporary directory.

\n

The created folder path is passed as a string to the callback's second\nparameter.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use.

\n

Example:

\n
fs.mkdtemp('/tmp/foo-', (err, folder) => {\n  if (err) throw err;\n  console.log(folder);\n  // Prints: /tmp/foo-itXde2\n});\n
\n

Note: The fs.mkdtemp() method will append the six randomly selected\ncharacters directly to the prefix string. For instance, given a directory\n/tmp, if the intention is to create a temporary directory within /tmp,\nthe prefix must end with a trailing platform-specific path separator\n(require('path').sep).

\n
// The parent directory for the new temporary directory\nconst tmpDir = '/tmp';\n\n// This method is *INCORRECT*:\nfs.mkdtemp(tmpDir, (err, folder) => {\n  if (err) throw err;\n  console.log(folder);\n  // Will print something similar to `/tmpabc123`.\n  // Note that a new temporary directory is created\n  // at the file system root rather than *within*\n  // the /tmp directory.\n});\n\n// This method is *CORRECT*:\nconst path = require('path');\nfs.mkdtemp(tmpDir + path.sep, (err, folder) => {\n  if (err) throw err;\n  console.log(folder);\n  // Will print something similar to `/tmp/abc123`.\n  // A new temporary directory is created within\n  // the /tmp directory.\n});\n
\n" }, { "textRaw": "fs.mkdtempSync(prefix[, options])", "type": "method", "name": "mkdtempSync", "meta": { "added": [ "v5.10.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`prefix` {String} ", "name": "prefix", "type": "String" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true } ] }, { "params": [ { "name": "prefix" }, { "name": "options", "optional": true } ] } ], "desc": "

The synchronous version of fs.mkdtemp(). Returns the created\nfolder path.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use.

\n" }, { "textRaw": "fs.open(path, flags[, mode], callback)", "type": "method", "name": "open", "meta": { "added": [ "v0.0.2" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`flags` {String | Number} ", "name": "flags", "type": "String | Number" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "flags" }, { "name": "mode", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronous file open. See open(2). flags can be:

\n\n

mode sets the file mode (permission and sticky bits), but only if the file was\ncreated. It defaults to 0666, readable and writable.

\n

The callback gets two arguments (err, fd).

\n

The exclusive flag 'x' (O_EXCL flag in open(2)) ensures that path is newly\ncreated. On POSIX systems, path is considered to exist even if it is a symlink\nto a non-existent file. The exclusive flag may or may not work with network file\nsystems.

\n

flags can also be a number as documented by open(2); commonly used constants\nare available from fs.constants. On Windows, flags are translated to\ntheir equivalent ones where applicable, e.g. O_WRONLY to FILE_GENERIC_WRITE,\nor O_EXCL|O_CREAT to CREATE_NEW, as accepted by CreateFileW.

\n

On Linux, positional writes don't work when the file is opened in append mode.\nThe kernel ignores the position argument and always appends the data to\nthe end of the file.

\n

Note: The behavior of fs.open() is platform specific for some flags. As such,\nopening a directory on OS X and Linux with the 'a+' flag - see example below -\nwill return an error. In contrast, on Windows and FreeBSD, a file descriptor\nwill be returned.

\n
// OS X and Linux\nfs.open('<directory>', 'a+', (err, fd) => {\n  // => [Error: EISDIR: illegal operation on a directory, open <directory>]\n});\n\n// Windows and FreeBSD\nfs.open('<directory>', 'a+', (err, fd) => {\n  // => null, <fd>\n});\n
\n" }, { "textRaw": "fs.openSync(path, flags[, mode])", "type": "method", "name": "openSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`flags` {String | Number} ", "name": "flags", "type": "String | Number" }, { "textRaw": "`mode` {Integer} ", "name": "mode", "type": "Integer", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "flags" }, { "name": "mode", "optional": true } ] } ], "desc": "

Synchronous version of fs.open(). Returns an integer representing the file\ndescriptor.

\n" }, { "textRaw": "fs.read(fd, buffer, offset, length, position, callback)", "type": "method", "name": "read", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.4.0", "pr-url": "https://github.com/nodejs/node/pull/10382", "description": "The `buffer` parameter can now be a `Uint8Array`." }, { "version": "v6.0.0", "pr-url": "https://github.com/nodejs/node/pull/4518", "description": "The `length` parameter can now be `0`." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`buffer` {String | Buffer | Uint8Array} ", "name": "buffer", "type": "String | Buffer | Uint8Array" }, { "textRaw": "`offset` {Integer} ", "name": "offset", "type": "Integer" }, { "textRaw": "`length` {Integer} ", "name": "length", "type": "Integer" }, { "textRaw": "`position` {Integer} ", "name": "position", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "buffer" }, { "name": "offset" }, { "name": "length" }, { "name": "position" }, { "name": "callback" } ] } ], "desc": "

Read data from the file specified by fd.

\n

buffer is the buffer that the data will be written to.

\n

offset is the offset in the buffer to start writing at.

\n

length is an integer specifying the number of bytes to read.

\n

position is an integer specifying where to begin reading from in the file.\nIf position is null, data will be read from the current file position.

\n

The callback is given the three arguments, (err, bytesRead, buffer).

\n" }, { "textRaw": "fs.readdir(path[, options], callback)", "type": "method", "name": "readdir", "meta": { "added": [ "v0.1.8" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronous readdir(3). Reads the contents of a directory.\nThe callback gets two arguments (err, files) where files is an array of\nthe names of the files in the directory excluding '.' and '..'.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use for\nthe filenames passed to the callback. If the encoding is set to 'buffer',\nthe filenames returned will be passed as Buffer objects.

\n" }, { "textRaw": "fs.readdirSync(path[, options])", "type": "method", "name": "readdirSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true } ] } ], "desc": "

Synchronous readdir(3). Returns an array of filenames excluding '.' and\n'..'.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use for\nthe filenames passed to the callback. If the encoding is set to 'buffer',\nthe filenames returned will be passed as Buffer objects.

\n" }, { "textRaw": "fs.readFile(file[, options], callback)", "type": "method", "name": "readFile", "meta": { "added": [ "v0.1.29" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v5.1.0", "pr-url": "https://github.com/nodejs/node/pull/3740", "description": "The `callback` will always be called with `null` as the `error` parameter in case of success." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/3163", "description": "The `file` parameter can be a file descriptor now." } ] }, "signatures": [ { "params": [ { "textRaw": "`file` {String | Buffer | Integer} filename or file descriptor ", "name": "file", "type": "String | Buffer | Integer", "desc": "filename or file descriptor" }, { "textRaw": "`options` {Object | String} ", "options": [ { "textRaw": "`encoding` {String | Null} default = `null` ", "name": "encoding", "type": "String | Null", "desc": "default = `null`" }, { "textRaw": "`flag` {String} default = `'r'` ", "name": "flag", "type": "String", "desc": "default = `'r'`" } ], "name": "options", "type": "Object | String", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "file" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronously reads the entire contents of a file. Example:

\n
fs.readFile('/etc/passwd', (err, data) => {\n  if (err) throw err;\n  console.log(data);\n});\n
\n

The callback is passed two arguments (err, data), where data is the\ncontents of the file.

\n

If no encoding is specified, then the raw buffer is returned.

\n

If options is a string, then it specifies the encoding. Example:

\n
fs.readFile('/etc/passwd', 'utf8', callback);\n
\n

Any specified file descriptor has to support reading.

\n

Note: If a file descriptor is specified as the file, it will not be closed\nautomatically.

\n" }, { "textRaw": "fs.readFileSync(file[, options])", "type": "method", "name": "readFileSync", "meta": { "added": [ "v0.1.8" ], "changes": [ { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/3163", "description": "The `file` parameter can be a file descriptor now." } ] }, "signatures": [ { "params": [ { "textRaw": "`file` {String | Buffer | Integer} filename or file descriptor ", "name": "file", "type": "String | Buffer | Integer", "desc": "filename or file descriptor" }, { "textRaw": "`options` {Object | String} ", "options": [ { "textRaw": "`encoding` {String | Null} default = `null` ", "name": "encoding", "type": "String | Null", "desc": "default = `null`" }, { "textRaw": "`flag` {String} default = `'r'` ", "name": "flag", "type": "String", "desc": "default = `'r'`" } ], "name": "options", "type": "Object | String", "optional": true } ] }, { "params": [ { "name": "file" }, { "name": "options", "optional": true } ] } ], "desc": "

Synchronous version of fs.readFile. Returns the contents of the file.

\n

If the encoding option is specified then this function returns a\nstring. Otherwise it returns a buffer.

\n" }, { "textRaw": "fs.readlink(path[, options], callback)", "type": "method", "name": "readlink", "meta": { "added": [ "v0.1.31" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronous readlink(2). The callback gets two arguments (err,\nlinkString).

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use for\nthe link path passed to the callback. If the encoding is set to 'buffer',\nthe link path returned will be passed as a Buffer object.

\n" }, { "textRaw": "fs.readlinkSync(path[, options])", "type": "method", "name": "readlinkSync", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true } ] } ], "desc": "

Synchronous readlink(2). Returns the symbolic link's string value.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use for\nthe link path passed to the callback. If the encoding is set to 'buffer',\nthe link path returned will be passed as a Buffer object.

\n" }, { "textRaw": "fs.readSync(fd, buffer, offset, length, position)", "type": "method", "name": "readSync", "meta": { "added": [ "v0.1.21" ], "changes": [ { "version": "v6.0.0", "pr-url": "https://github.com/nodejs/node/pull/4518", "description": "The `length` parameter can now be `0`." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`buffer` {String | Buffer | Uint8Array} ", "name": "buffer", "type": "String | Buffer | Uint8Array" }, { "textRaw": "`offset` {Integer} ", "name": "offset", "type": "Integer" }, { "textRaw": "`length` {Integer} ", "name": "length", "type": "Integer" }, { "textRaw": "`position` {Integer} ", "name": "position", "type": "Integer" } ] }, { "params": [ { "name": "fd" }, { "name": "buffer" }, { "name": "offset" }, { "name": "length" }, { "name": "position" } ] } ], "desc": "

Synchronous version of fs.read(). Returns the number of bytesRead.

\n" }, { "textRaw": "fs.realpath(path[, options], callback)", "type": "method", "name": "realpath", "meta": { "added": [ "v0.1.31" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v6.4.0", "pr-url": "https://github.com/nodejs/node/pull/7899", "description": "Calling `realpath` now works again for various edge cases on Windows." }, { "version": "v6.0.0", "pr-url": "https://github.com/nodejs/node/pull/3594", "description": "The `cache` parameter was removed." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronous realpath(3). The callback gets two arguments (err,\nresolvedPath). May use process.cwd to resolve relative paths.

\n

Only paths that can be converted to UTF8 strings are supported.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use for\nthe path passed to the callback. If the encoding is set to 'buffer',\nthe path returned will be passed as a Buffer object.

\n" }, { "textRaw": "fs.realpathSync(path[, options])", "type": "method", "name": "realpathSync", "meta": { "added": [ "v0.1.31" ], "changes": [ { "version": "v6.4.0", "pr-url": "https://github.com/nodejs/node/pull/7899", "description": "Calling `realpathSync` now works again for various edge cases on Windows." }, { "version": "v6.0.0", "pr-url": "https://github.com/nodejs/node/pull/3594", "description": "The `cache` parameter was removed." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer}; ", "name": "path", "type": "String | Buffer", "desc": ";" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`encoding` {String} default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "options", "optional": true } ] } ], "desc": "

Synchronous realpath(3). Returns the resolved path.

\n

Only paths that can be converted to UTF8 strings are supported.

\n

The optional options argument can be a string specifying an encoding, or an\nobject with an encoding property specifying the character encoding to use for\nthe returned value. If the encoding is set to 'buffer', the path returned\nwill be passed as a Buffer object.

\n" }, { "textRaw": "fs.rename(oldPath, newPath, callback)", "type": "method", "name": "rename", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`oldPath` {String | Buffer} ", "name": "oldPath", "type": "String | Buffer" }, { "textRaw": "`newPath` {String | Buffer} ", "name": "newPath", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "oldPath" }, { "name": "newPath" }, { "name": "callback" } ] } ], "desc": "

Asynchronous rename(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.renameSync(oldPath, newPath)", "type": "method", "name": "renameSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`oldPath` {String | Buffer} ", "name": "oldPath", "type": "String | Buffer" }, { "textRaw": "`newPath` {String | Buffer} ", "name": "newPath", "type": "String | Buffer" } ] }, { "params": [ { "name": "oldPath" }, { "name": "newPath" } ] } ], "desc": "

Synchronous rename(2). Returns undefined.

\n" }, { "textRaw": "fs.rmdir(path, callback)", "type": "method", "name": "rmdir", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "callback" } ] } ], "desc": "

Asynchronous rmdir(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.rmdirSync(path)", "type": "method", "name": "rmdirSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" } ] }, { "params": [ { "name": "path" } ] } ], "desc": "

Synchronous rmdir(2). Returns undefined.

\n" }, { "textRaw": "fs.stat(path, callback)", "type": "method", "name": "stat", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "callback" } ] } ], "desc": "

Asynchronous stat(2). The callback gets two arguments (err, stats) where\nstats is an fs.Stats object.

\n

In case of an error, the err.code will be one of Common System Errors.

\n

Using fs.stat() to check for the existence of a file before calling\nfs.open(), fs.readFile() or fs.writeFile() is not recommended.\nInstead, user code should open/read/write the file directly and handle the\nerror raised if the file is not available.

\n

To check if a file exists without manipulating it afterwards, fs.access()\nis recommended.

\n" }, { "textRaw": "fs.statSync(path)", "type": "method", "name": "statSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" } ] }, { "params": [ { "name": "path" } ] } ], "desc": "

Synchronous stat(2). Returns an instance of fs.Stats.

\n" }, { "textRaw": "fs.symlink(target, path[, type], callback)", "type": "method", "name": "symlink", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`target` {String | Buffer} ", "name": "target", "type": "String | Buffer" }, { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`type` {String} ", "name": "type", "type": "String", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "target" }, { "name": "path" }, { "name": "type", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronous symlink(2). No arguments other than a possible exception are given\nto the completion callback. The type argument can be set to 'dir',\n'file', or 'junction' (default is 'file') and is only available on\nWindows (ignored on other platforms). Note that Windows junction points require\nthe destination path to be absolute. When using 'junction', the target\nargument will automatically be normalized to absolute path.

\n

Here is an example below:

\n
fs.symlink('./foo', './new-port');\n
\n

It creates a symbolic link named "new-port" that points to "foo".

\n" }, { "textRaw": "fs.symlinkSync(target, path[, type])", "type": "method", "name": "symlinkSync", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`target` {String | Buffer} ", "name": "target", "type": "String | Buffer" }, { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`type` {String} ", "name": "type", "type": "String", "optional": true } ] }, { "params": [ { "name": "target" }, { "name": "path" }, { "name": "type", "optional": true } ] } ], "desc": "

Synchronous symlink(2). Returns undefined.

\n" }, { "textRaw": "fs.truncate(path, len, callback)", "type": "method", "name": "truncate", "meta": { "added": [ "v0.8.6" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`len` {Integer} default = `0` ", "name": "len", "type": "Integer", "desc": "default = `0`" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "len" }, { "name": "callback" } ] } ], "desc": "

Asynchronous truncate(2). No arguments other than a possible exception are\ngiven to the completion callback. A file descriptor can also be passed as the\nfirst argument. In this case, fs.ftruncate() is called.

\n" }, { "textRaw": "fs.truncateSync(path, len)", "type": "method", "name": "truncateSync", "meta": { "added": [ "v0.8.6" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`len` {Integer} default = `0` ", "name": "len", "type": "Integer", "desc": "default = `0`" } ] }, { "params": [ { "name": "path" }, { "name": "len" } ] } ], "desc": "

Synchronous truncate(2). Returns undefined. A file descriptor can also be\npassed as the first argument. In this case, fs.ftruncateSync() is called.

\n" }, { "textRaw": "fs.unlink(path, callback)", "type": "method", "name": "unlink", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "callback" } ] } ], "desc": "

Asynchronous unlink(2). No arguments other than a possible exception are given\nto the completion callback.

\n" }, { "textRaw": "fs.unlinkSync(path)", "type": "method", "name": "unlinkSync", "meta": { "added": [ "v0.1.21" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" } ] }, { "params": [ { "name": "path" } ] } ], "desc": "

Synchronous unlink(2). Returns undefined.

\n" }, { "textRaw": "fs.unwatchFile(filename[, listener])", "type": "method", "name": "unwatchFile", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`filename` {String | Buffer} ", "name": "filename", "type": "String | Buffer" }, { "textRaw": "`listener` {Function} ", "name": "listener", "type": "Function", "optional": true } ] }, { "params": [ { "name": "filename" }, { "name": "listener", "optional": true } ] } ], "desc": "

Stop watching for changes on filename. If listener is specified, only that\nparticular listener is removed. Otherwise, all listeners are removed and you\nhave effectively stopped watching filename.

\n

Calling fs.unwatchFile() with a filename that is not being watched is a\nno-op, not an error.

\n

Note: fs.watch() is more efficient than fs.watchFile() and fs.unwatchFile().\nfs.watch() should be used instead of fs.watchFile() and fs.unwatchFile()\nwhen possible.

\n" }, { "textRaw": "fs.utimes(path, atime, mtime, callback)", "type": "method", "name": "utimes", "meta": { "added": [ "v0.4.2" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v4.1.0", "pr-url": "https://github.com/nodejs/node/pull/2387", "description": "Numeric strings, `NaN` and `Infinity` are now allowed time specifiers." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`atime` {Integer} ", "name": "atime", "type": "Integer" }, { "textRaw": "`mtime` {Integer} ", "name": "mtime", "type": "Integer" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "path" }, { "name": "atime" }, { "name": "mtime" }, { "name": "callback" } ] } ], "desc": "

Change file timestamps of the file referenced by the supplied path.

\n

Note: the arguments atime and mtime of the following related functions\nfollow these rules:

\n\n" }, { "textRaw": "fs.utimesSync(path, atime, mtime)", "type": "method", "name": "utimesSync", "meta": { "added": [ "v0.4.2" ], "changes": [ { "version": "v4.1.0", "pr-url": "https://github.com/nodejs/node/pull/2387", "description": "Numeric strings, `NaN` and `Infinity` are now allowed time specifiers." } ] }, "signatures": [ { "params": [ { "textRaw": "`path` {String | Buffer} ", "name": "path", "type": "String | Buffer" }, { "textRaw": "`atime` {Integer} ", "name": "atime", "type": "Integer" }, { "textRaw": "`mtime` {Integer} ", "name": "mtime", "type": "Integer" } ] }, { "params": [ { "name": "path" }, { "name": "atime" }, { "name": "mtime" } ] } ], "desc": "

Synchronous version of fs.utimes(). Returns undefined.

\n" }, { "textRaw": "fs.watch(filename[, options][, listener])", "type": "method", "name": "watch", "meta": { "added": [ "v0.5.10" ], "changes": [ { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7831", "description": "The passed `options` object will never be modified." } ] }, "signatures": [ { "params": [ { "textRaw": "`filename` {String | Buffer} ", "name": "filename", "type": "String | Buffer" }, { "textRaw": "`options` {String | Object} ", "options": [ { "textRaw": "`persistent` {Boolean} Indicates whether the process should continue to run as long as files are being watched. default = `true` ", "name": "persistent", "type": "Boolean", "desc": "Indicates whether the process should continue to run as long as files are being watched. default = `true`" }, { "textRaw": "`recursive` {Boolean} Indicates whether all subdirectories should be watched, or only the current directory. The applies when a directory is specified, and only on supported platforms (See [Caveats][]). default = `false` ", "name": "recursive", "type": "Boolean", "desc": "Indicates whether all subdirectories should be watched, or only the current directory. The applies when a directory is specified, and only on supported platforms (See [Caveats][]). default = `false`" }, { "textRaw": "`encoding` {String} Specifies the character encoding to be used for the filename passed to the listener. default = `'utf8'` ", "name": "encoding", "type": "String", "desc": "Specifies the character encoding to be used for the filename passed to the listener. default = `'utf8'`" } ], "name": "options", "type": "String | Object", "optional": true }, { "textRaw": "`listener` {Function} ", "name": "listener", "type": "Function", "optional": true } ] }, { "params": [ { "name": "filename" }, { "name": "options", "optional": true }, { "name": "listener", "optional": true } ] } ], "desc": "

Watch for changes on filename, where filename is either a file or a\ndirectory. The returned object is a fs.FSWatcher.

\n

The second argument is optional. If options is provided as a string, it\nspecifies the encoding. Otherwise options should be passed as an object.

\n

The listener callback gets two arguments (eventType, filename). eventType is either\n'rename' or 'change', and filename is the name of the file which triggered\nthe event.

\n

Note that on most platforms, 'rename' is emitted whenever a filename appears\nor disappears in the directory.

\n

Also note the listener callback is attached to the 'change' event fired by\nfs.FSWatcher, but it is not the same thing as the 'change' value of\neventType.

\n", "miscs": [ { "textRaw": "Caveats", "name": "Caveats", "type": "misc", "desc": "

The fs.watch API is not 100% consistent across platforms, and is\nunavailable in some situations.

\n

The recursive option is only supported on OS X and Windows.

\n", "miscs": [ { "textRaw": "Availability", "name": "Availability", "type": "misc", "desc": "

This feature depends on the underlying operating system providing a way\nto be notified of filesystem changes.

\n\n

If the underlying functionality is not available for some reason, then\nfs.watch will not be able to function. For example, watching files or\ndirectories can be unreliable, and in some cases impossible, on network file\nsystems (NFS, SMB, etc), or host file systems when using virtualization software\nsuch as Vagrant, Docker, etc.

\n

You can still use fs.watchFile, which uses stat polling, but it is slower and\nless reliable.

\n" }, { "textRaw": "Inodes", "name": "Inodes", "type": "misc", "desc": "

On Linux and OS X systems, fs.watch() resolves the path to an inode and\nwatches the inode. If the watched path is deleted and recreated, it is assigned\na new inode. The watch will emit an event for the delete but will continue\nwatching the original inode. Events for the new inode will not be emitted.\nThis is expected behavior.

\n

In AIX, save and close of a file being watched causes two notifications -\none for adding new content, and one for truncation. Moreover, save and\nclose operations on some platforms cause inode changes that force watch\noperations to become invalid and ineffective. AIX retains inode for the\nlifetime of a file, that way though this is different from Linux / OS X,\nthis improves the usability of file watching. This is expected behavior.

\n" }, { "textRaw": "Filename Argument", "name": "Filename Argument", "type": "misc", "desc": "

Providing filename argument in the callback is only supported on Linux and\nWindows. Even on supported platforms, filename is not always guaranteed to\nbe provided. Therefore, don't assume that filename argument is always\nprovided in the callback, and have some fallback logic if it is null.

\n
fs.watch('somedir', (eventType, filename) => {\n  console.log(`event type is: ${eventType}`);\n  if (filename) {\n    console.log(`filename provided: ${filename}`);\n  } else {\n    console.log('filename not provided');\n  }\n});\n
\n" } ] } ] }, { "textRaw": "fs.watchFile(filename[, options], listener)", "type": "method", "name": "watchFile", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`filename` {String | Buffer} ", "name": "filename", "type": "String | Buffer" }, { "textRaw": "`options` {Object} ", "options": [ { "textRaw": "`persistent` {Boolean} ", "name": "persistent", "type": "Boolean" }, { "textRaw": "`interval` {Integer} ", "name": "interval", "type": "Integer" } ], "name": "options", "type": "Object", "optional": true }, { "textRaw": "`listener` {Function} ", "name": "listener", "type": "Function" } ] }, { "params": [ { "name": "filename" }, { "name": "options", "optional": true }, { "name": "listener" } ] } ], "desc": "

Watch for changes on filename. The callback listener will be called each\ntime the file is accessed.

\n

The options argument may be omitted. If provided, it should be an object. The\noptions object may contain a boolean named persistent that indicates\nwhether the process should continue to run as long as files are being watched.\nThe options object may specify an interval property indicating how often the\ntarget should be polled in milliseconds. The default is\n{ persistent: true, interval: 5007 }.

\n

The listener gets two arguments the current stat object and the previous\nstat object:

\n
fs.watchFile('message.text', (curr, prev) => {\n  console.log(`the current mtime is: ${curr.mtime}`);\n  console.log(`the previous mtime was: ${prev.mtime}`);\n});\n
\n

These stat objects are instances of fs.Stat.

\n

If you want to be notified when the file was modified, not just accessed,\nyou need to compare curr.mtime and prev.mtime.

\n

Note: when an fs.watchFile operation results in an ENOENT error, it will\n invoke the listener once, with all the fields zeroed (or, for dates, the Unix\n Epoch). In Windows, blksize and blocks fields will be undefined, instead\n of zero. If the file is created later on, the listener will be called again,\n with the latest stat objects. This is a change in functionality since v0.10.

\n

Note: fs.watch() is more efficient than fs.watchFile and\nfs.unwatchFile. fs.watch should be used instead of fs.watchFile and\nfs.unwatchFile when possible.

\n" }, { "textRaw": "fs.write(fd, buffer[, offset[, length[, position]]], callback)", "type": "method", "name": "write", "meta": { "added": [ "v0.0.2" ], "changes": [ { "version": "v7.4.0", "pr-url": "https://github.com/nodejs/node/pull/10382", "description": "The `buffer` parameter can now be a `Uint8Array`." }, { "version": "v7.2.0", "pr-url": "https://github.com/nodejs/node/pull/7856", "description": "The `offset` and `length` parameters are optional now." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`buffer` {Buffer | Uint8Array} ", "name": "buffer", "type": "Buffer | Uint8Array" }, { "textRaw": "`offset` {Integer} ", "name": "offset", "type": "Integer", "optional": true }, { "textRaw": "`length` {Integer} ", "name": "length", "type": "Integer", "optional": true }, { "textRaw": "`position` {Integer} ", "name": "position", "type": "Integer", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "buffer" }, { "name": "offset", "optional": true }, { "name": "length", "optional": true }, { "name": "position", "optional": true }, { "name": "callback" } ] } ], "desc": "

Write buffer to the file specified by fd.

\n

offset determines the part of the buffer to be written, and length is\nan integer specifying the number of bytes to write.

\n

position refers to the offset from the beginning of the file where this data\nshould be written. If typeof position !== 'number', the data will be written\nat the current position. See pwrite(2).

\n

The callback will be given three arguments (err, written, buffer) where\nwritten specifies how many bytes were written from buffer.

\n

Note that it is unsafe to use fs.write multiple times on the same file\nwithout waiting for the callback. For this scenario,\nfs.createWriteStream is strongly recommended.

\n

On Linux, positional writes don't work when the file is opened in append mode.\nThe kernel ignores the position argument and always appends the data to\nthe end of the file.

\n" }, { "textRaw": "fs.write(fd, string[, position[, encoding]], callback)", "type": "method", "name": "write", "meta": { "added": [ "v0.11.5" ], "changes": [ { "version": "v7.2.0", "pr-url": "https://github.com/nodejs/node/pull/7856", "description": "The `position` parameter is optional now." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`string` {String} ", "name": "string", "type": "String" }, { "textRaw": "`position` {Integer} ", "name": "position", "type": "Integer", "optional": true }, { "textRaw": "`encoding` {String} ", "name": "encoding", "type": "String", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "fd" }, { "name": "string" }, { "name": "position", "optional": true }, { "name": "encoding", "optional": true }, { "name": "callback" } ] } ], "desc": "

Write string to the file specified by fd. If string is not a string, then\nthe value will be coerced to one.

\n

position refers to the offset from the beginning of the file where this data\nshould be written. If typeof position !== 'number' the data will be written at\nthe current position. See pwrite(2).

\n

encoding is the expected string encoding.

\n

The callback will receive the arguments (err, written, string) where written\nspecifies how many bytes the passed string required to be written. Note that\nbytes written is not the same as string characters. See Buffer.byteLength.

\n

Unlike when writing buffer, the entire string must be written. No substring\nmay be specified. This is because the byte offset of the resulting data may not\nbe the same as the string offset.

\n

Note that it is unsafe to use fs.write multiple times on the same file\nwithout waiting for the callback. For this scenario,\nfs.createWriteStream is strongly recommended.

\n

On Linux, positional writes don't work when the file is opened in append mode.\nThe kernel ignores the position argument and always appends the data to\nthe end of the file.

\n" }, { "textRaw": "fs.writeFile(file, data[, options], callback)", "type": "method", "name": "writeFile", "meta": { "added": [ "v0.1.29" ], "changes": [ { "version": "v7.4.0", "pr-url": "https://github.com/nodejs/node/pull/10382", "description": "The `data` parameter can now be a `Uint8Array`." }, { "version": "v7.0.0", "pr-url": "https://github.com/nodejs/node/pull/7897", "description": "The `callback` parameter is no longer optional. Not passing it will emit a deprecation warning." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/3163", "description": "The `file` parameter can be a file descriptor now." } ] }, "signatures": [ { "params": [ { "textRaw": "`file` {String | Buffer | Integer} filename or file descriptor ", "name": "file", "type": "String | Buffer | Integer", "desc": "filename or file descriptor" }, { "textRaw": "`data` {String | Buffer | Uint8Array} ", "name": "data", "type": "String | Buffer | Uint8Array" }, { "textRaw": "`options` {Object | String} ", "options": [ { "textRaw": "`encoding` {String | Null} default = `'utf8'` ", "name": "encoding", "type": "String | Null", "desc": "default = `'utf8'`" }, { "textRaw": "`mode` {Integer} default = `0o666` ", "name": "mode", "type": "Integer", "desc": "default = `0o666`" }, { "textRaw": "`flag` {String} default = `'w'` ", "name": "flag", "type": "String", "desc": "default = `'w'`" } ], "name": "options", "type": "Object | String", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" } ] }, { "params": [ { "name": "file" }, { "name": "data" }, { "name": "options", "optional": true }, { "name": "callback" } ] } ], "desc": "

Asynchronously writes data to a file, replacing the file if it already exists.\ndata can be a string or a buffer.

\n

The encoding option is ignored if data is a buffer. It defaults\nto 'utf8'.

\n

Example:

\n
fs.writeFile('message.txt', 'Hello Node.js', (err) => {\n  if (err) throw err;\n  console.log('It\\'s saved!');\n});\n
\n

If options is a string, then it specifies the encoding. Example:

\n
fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);\n
\n

Any specified file descriptor has to support writing.

\n

Note that it is unsafe to use fs.writeFile multiple times on the same file\nwithout waiting for the callback. For this scenario,\nfs.createWriteStream is strongly recommended.

\n

Note: If a file descriptor is specified as the file, it will not be closed\nautomatically.

\n" }, { "textRaw": "fs.writeFileSync(file, data[, options])", "type": "method", "name": "writeFileSync", "meta": { "added": [ "v0.1.29" ], "changes": [ { "version": "v7.4.0", "pr-url": "https://github.com/nodejs/node/pull/10382", "description": "The `data` parameter can now be a `Uint8Array`." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/3163", "description": "The `file` parameter can be a file descriptor now." } ] }, "signatures": [ { "params": [ { "textRaw": "`file` {String | Buffer | Integer} filename or file descriptor ", "name": "file", "type": "String | Buffer | Integer", "desc": "filename or file descriptor" }, { "textRaw": "`data` {String | Buffer | Uint8Array} ", "name": "data", "type": "String | Buffer | Uint8Array" }, { "textRaw": "`options` {Object | String} ", "options": [ { "textRaw": "`encoding` {String | Null} default = `'utf8'` ", "name": "encoding", "type": "String | Null", "desc": "default = `'utf8'`" }, { "textRaw": "`mode` {Integer} default = `0o666` ", "name": "mode", "type": "Integer", "desc": "default = `0o666`" }, { "textRaw": "`flag` {String} default = `'w'` ", "name": "flag", "type": "String", "desc": "default = `'w'`" } ], "name": "options", "type": "Object | String", "optional": true } ] }, { "params": [ { "name": "file" }, { "name": "data" }, { "name": "options", "optional": true } ] } ], "desc": "

The synchronous version of fs.writeFile(). Returns undefined.

\n" }, { "textRaw": "fs.writeSync(fd, buffer[, offset[, length[, position]]])", "type": "method", "name": "writeSync", "meta": { "added": [ "v0.1.21" ], "changes": [ { "version": "v7.4.0", "pr-url": "https://github.com/nodejs/node/pull/10382", "description": "The `buffer` parameter can now be a `Uint8Array`." }, { "version": "v7.2.0", "pr-url": "https://github.com/nodejs/node/pull/7856", "description": "The `offset` and `length` parameters are optional now." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`buffer` {Buffer | Uint8Array} ", "name": "buffer", "type": "Buffer | Uint8Array" }, { "textRaw": "`offset` {Integer} ", "name": "offset", "type": "Integer", "optional": true }, { "textRaw": "`length` {Integer} ", "name": "length", "type": "Integer", "optional": true }, { "textRaw": "`position` {Integer} ", "name": "position", "type": "Integer", "optional": true } ] }, { "params": [ { "name": "fd" }, { "name": "buffer" }, { "name": "offset", "optional": true }, { "name": "length", "optional": true }, { "name": "position", "optional": true } ] } ], "desc": "

Synchronous versions of fs.write(). Returns the number of bytes written.

\n" }, { "textRaw": "fs.writeSync(fd, string[, position[, encoding]])", "type": "method", "name": "writeSync", "meta": { "added": [ "v0.11.5" ], "changes": [ { "version": "v7.2.0", "pr-url": "https://github.com/nodejs/node/pull/7856", "description": "The `position` parameter is optional now." } ] }, "signatures": [ { "params": [ { "textRaw": "`fd` {Integer} ", "name": "fd", "type": "Integer" }, { "textRaw": "`string` {String} ", "name": "string", "type": "String" }, { "textRaw": "`position` {Integer} ", "name": "position", "type": "Integer", "optional": true }, { "textRaw": "`encoding` {String} ", "name": "encoding", "type": "String", "optional": true } ] }, { "params": [ { "name": "fd" }, { "name": "string" }, { "name": "position", "optional": true }, { "name": "encoding", "optional": true } ] } ], "desc": "

Synchronous versions of fs.write(). Returns the number of bytes written.

\n" } ], "properties": [ { "textRaw": "fs.constants", "name": "constants", "desc": "

Returns an object containing commonly used constants for file system\noperations. The specific constants currently defined are described in\nFS Constants.

\n" } ], "type": "module", "displayName": "fs" } ] }