Like fs.openSync()
but does not interfere with the provided pathname.
Useful to open special files like CONOUT$
, \\.\nul
, etc.
npm install --save fs-open-sync
This module exports a single function that works like fs.openSync()
.
-
path
{Buffer|string} The file pathname. -
flags
{number|string} The access mode. Defaults to'r'
. -
mode
{number|string} The file mode bits to be applied when a new file is created. Defaults to0o666
.
An integer representing the file descriptor.
Throws a RangeError
or TypeError
if an argument in not valid or an Error
if the file cannot be opened.
import open from 'fs-open-sync'; // Also available as a named export.
import { fileURLToPath } from 'node:url';
import { ok } from 'node:assert';
const __filename = fileURLToPath(import.meta.url);
const fd = open(__filename);
ok(fd > 0);