Skip to main content

open

function open
Jump to headingopen(
path: PathLike,
flags: OpenMode | undefined,
mode:
Mode
| undefined
| null
,
callback: (
err: ErrnoException | null,
fd: number,
) => void
,
): void

Asynchronous file open. See the POSIX open(2) documentation for more details.

mode sets the file mode (permission and sticky bits), but only if the file was created. On Windows, only the write permission can be manipulated; see chmod.

The callback gets two arguments (err, fd).

Some characters (< > : " / \ | ? *) are reserved under Windows as documented by Naming Files, Paths, and Namespaces. Under NTFS, if the filename contains a colon, Node.js will open a file system stream, as described by this MSDN page.

Functions based on fs.open() exhibit this behavior as well:fs.writeFile(), fs.readFile(), etc.

Parameters Jump to heading

optional
Jump to headingflags: OpenMode | undefined = 'r'

See support of file system flags``.

optional
Jump to headingmode:
Mode
| undefined
| null
= 0o666
Jump to headingcallback: (
err: ErrnoException | null,
fd: number,
) => void

Return Type Jump to heading

void
Jump to headingopen(
path: PathLike,
flags: OpenMode | undefined,
callback: (
err: ErrnoException | null,
fd: number,
) => void
,
): void

Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be 0o666.

Parameters Jump to heading

A path to a file. If a URL is provided, it must use the file: protocol.

optional
Jump to headingflags: OpenMode | undefined = 'r'

See support of file system flags``.

Jump to headingcallback: (
err: ErrnoException | null,
fd: number,
) => void

Return Type Jump to heading

void
Jump to headingopen(
path: PathLike,
callback: (
err: ErrnoException | null,
fd: number,
) => void
,
): void

Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be 0o666.

Parameters Jump to heading

A path to a file. If a URL is provided, it must use the file: protocol.

Jump to headingcallback: (
err: ErrnoException | null,
fd: number,
) => void

Return Type Jump to heading

void
Back to top