Members
(static) S_IFBLK :number
- Source:
- Default Value:
- 24576
File node type: block device
Type:
- number
(static) S_IFCHR :number
- Source:
- Default Value:
- 8192
File node type: char device
Type:
- number
(static) S_IFDIR :number
- Source:
- Default Value:
- 16384
File node type: directory
Type:
- number
(static) S_IFIFO :number
- Source:
- Default Value:
- 4096
File node type: FIFO
Type:
- number
(static) S_IFLNK :number
- Source:
- Default Value:
- 40960
File node type: symbolic link
Type:
- number
(static) S_IFMT :number
- Source:
- Default Value:
- 61440
Used to & return of module:fs.stat to extract inode type
Type:
- number
(static) S_IFREG :number
- Source:
- Default Value:
- 32768
File node type: regular file
Type:
- number
(static) S_IFSOC :number
- Source:
- Default Value:
- 49152
File node type: socket
Type:
- number
Methods
(static) basename(path) → {string}
- Source:
Get the filename part of a path
Parameters:
Name | Type | Description |
---|---|---|
path |
string |
Returns:
- Type
- string
(static) chown(uid, gidopt) → {0}
- Source:
Change file owner and group of a file or symbolic link
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
uid |
number | The new owner |
|
gid |
number |
<optional> |
The new group (default is to leave untouched) |
Throws:
Returns:
- Type
- 0
(static) copy_file(from, to, modeopt) → {void}
- Source:
Copy file.
Note that if the copy fails, the target file is left in an undefined state.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
from |
string | Source file path |
||
to |
string | Destination file path |
||
mode |
number |
<optional> |
same as source file
|
File creation mode. Note that if the file exists its mode is left untouched. |
Throws:
Returns:
- Type
- void
(static) create_temp_file(contentsopt, modeopt) → {string}
- Source:
Create a temporary file with a random name
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
contents |
string |
<optional> |
''
|
Initial file contents |
mode |
number |
<optional> |
0600
|
Creation mode |
Throws:
Returns:
The temporary file path
- Type
- string
(static) dirname(path) → {string}
- Source:
Get the directory part of a path
Parameters:
Name | Type | Description |
---|---|---|
path |
string |
Returns:
A directory or '.' if none was present in parameter
- Type
- string
(static) exists(pathname) → {boolean}
- Source:
Check if a file path exists
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong
- Type
- SysError
Returns:
- Type
- boolean
(static) is_block_device(pathname) → {boolean}
- Source:
Check if a path points to a block device
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_char_device(pathname) → {boolean}
- Source:
Check if a path points to a char device
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_directory(pathname) → {boolean}
- Source:
Check if a path points to a directory
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_executable(pathname) → {boolean}
- Source:
Check if a file is executable by current process given its effective gid and uid.
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_fifo(pathname) → {boolean}
- Source:
Check if a path points to a FIFO
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_file(pathname) → {boolean}
- Source:
Check if a path points to a regular file
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_link(pathname) → {boolean}
- Source:
Check if a path points to a symbolic link
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_readable(pathname) → {boolean}
- Source:
Check if a file is readable by current process given its effective gid and uid.
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_socket(pathname) → {boolean}
- Source:
Check if a path points to a socket
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) is_writable(pathname) → {boolean}
- Source:
Check if a file is writable by current process given its effective gid and uid.
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string |
Throws:
-
If anything goes wrong or the path does not exist
- Type
- SysError
Returns:
- Type
- boolean
(static) join(…paths) → {string}
- Source:
- See:
Join several path parts and normalize the result
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
paths |
string |
<repeatable> |
Path parts to join |
Throws:
Returns:
- Type
- string
(static) list_dir(name, callbackopt) → {boolean|Array.<string>}
- Source:
List items of a directory (not including .
and ..
).
The order of listing is determined by the underlying filesystem.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Path of directory |
|
callback |
ListDirCallback |
<optional> |
A callback function invoked for each directory item. Use this idiom to avoid having to wait for the whole listing to finish. |
Throws:
Returns:
The list of items or, if a callback is provided, a boolean indicating if the listing finished (true) or was cancelled (false).
- Type
- boolean | Array.<string>
(static) mkdir(pathname, modeopt) → {0}
- Source:
Create a directory
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path of directory |
||
mode |
number |
<optional> |
0755
|
Creation mode |
Throws:
Returns:
- Type
- 0
(static) mkdirp(pathname, modeopt) → {0}
- Source:
Create a directory and all parents that are necessary
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path of directory |
||
mode |
number |
<optional> |
0755
|
Creation mode of new directories |
Throws:
Returns:
- Type
- 0
(static) mkfifo(pathname, modeopt) → {0}
- Source:
Create a FIFO at a given path
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path of FIFO |
||
mode |
number |
<optional> |
0644
|
Creation mode of FIFO |
Throws:
Returns:
- Type
- 0
(static) normalize_path(path) → {string}
- Source:
Normalize a path resolving any .
or ..
inside and making sure it is an
absolute path.
Note that this function does not return the canonical path (resolving symbolic links), just an absolute path in normalized form.
The path does NOT need to exist for the function to work (as opposed to module:fs.realpath.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | The path to normalize |
Returns:
An absolute path without any .
or ..
inside
- Type
- string
(static) read_file(path) → {string}
- Source:
- See:
Read the contents of a file as an UTF-8 string.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | Path of file to read |
Throws:
Returns:
The contents of the file as a string
- Type
- string
(static) read_link(path, dereferenceopt) → {string}
- Source:
Get the path referenced by a symbolic link
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
path |
string | Path to symbolic link |
||
dereference |
boolean |
<optional> |
true
|
Whether to dereference link if it is relative |
Throws:
Returns:
The target path
- Type
- string
(static) realpath(path) → {string}
- Source:
Get the canonical form of a path (resolving .
, ..
, and symbolic links)
Example
// Get the absolute path of the current working directory
const cwd = fs.realpath('.');
Parameters:
Name | Type | Description |
---|---|---|
path |
string |
Throws:
-
If anything goes wrong or path does not exist
- Type
- SysError
Returns:
The canonical path
- Type
- string
(static) rename(oldpath, newpath) → {0}
- Source:
Move a file or directory
Parameters:
Name | Type | Description |
---|---|---|
oldpath |
string | Path to rename |
newpath |
string | New path of renamed file/dir |
Throws:
Returns:
- Type
- 0
(static) rmdir(path, recursiveopt) → {0}
- Source:
Delete a directory
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
path |
string | Path of directory |
||
recursive |
boolean |
<optional> |
false
|
Delete even if not empty |
Throws:
Returns:
- Type
- 0
(static) stat(pathname) → {StatBuf}
- Source:
Obtain information of a file node
Parameters:
Name | Type | Description |
---|---|---|
pathname |
string | Path of file node |
Throws:
Returns:
Information on file node
- Type
- StatBuf
(static) symlink(path1, path2) → {0}
- Source:
Create a symbolic link at path2 pointing to path1
Parameters:
Name | Type | Description |
---|---|---|
path1 |
string | Symlink target path |
path2 |
string | Symlink file path |
Throws:
Returns:
- Type
- 0
(static) unlink(pathname, fail_if_not_foundopt) → {0}
- Source:
Delete a file node
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path of file node |
||
fail_if_not_found |
boolean |
<optional> |
true
|
Pass |
Throws:
Returns:
- Type
- 0
(static) write_file(path, contents, modeopt) → {number}
- Source:
- See:
Write a string in UTF-8 format to a file
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
path |
string | Path to file |
||
contents |
string | Contents of file |
||
mode |
number |
<optional> |
0644
|
Creation mode if file needs to be created |
Throws:
Returns:
The number of bytes written
- Type
- number