Skip to main content
open - node__fs.d.ts - Node documentation
function open

Usage in Deno

```typescript import { open } from "node:node__fs.d.ts"; ```
open(
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)`](http://man7.org/linux/man-pages/man2/open.2.html) 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](../.././node__fs.d.ts/~/chmod). The callback gets two arguments `(err, fd)`. Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams). Functions based on `fs.open()` exhibit this behavior as well:`fs.writeFile()`, `fs.readFile()`, etc.

Parameters

path: PathLike
optional
flags: OpenMode | undefined = 'r'
See `support of file system `flags``.
optional
mode:
Mode
| undefined
| null
= 0o666
callback: (
err: ErrnoException | null,
fd: number,
) => void

Return Type

void
open(
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

path: PathLike
A path to a file. If a URL is provided, it must use the `file:` protocol.
optional
flags: OpenMode | undefined = 'r'
See `support of file system `flags``.
callback: (
err: ErrnoException | null,
fd: number,
) => void

Return Type

void
open(
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

path: PathLike
A path to a file. If a URL is provided, it must use the `file:` protocol.
callback: (
err: ErrnoException | null,
fd: number,
) => void

Return Type

void