Node fs.readFileSync function | API Reference | Bun
BuildDocsReferenceGuidesBlogDiscord/
node:fs/
readFileSyncFreadFileSync
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
node:fs/
readFileSyncFreadFileSync
function
fs.readFileSync');
// => [Error: EISDIR: illegal operation on a directory, read ]
// FreeBSD
readFileSync(''); // =>
```" data-algolia-static="false" data-algolia-merged="false" data-type="Function">function
readFileSync(path:
PathOrFileDescriptor,options?: null | { encoding: null; flag: string }): NonSharedBuffer;
Returns the contents of the path.
For detailed information, see the documentation of the asynchronous version of this API: readFile.
If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
Similar to readFile, when the path is a directory, the behavior of fs.readFileSync() is platform-specific.
import { readFileSync } from 'node:fs';
// macOS, Linux, and Windows
readFileSync('');
// => [Error: EISDIR: illegal operation on a directory, read ]
// FreeBSD
readFileSync(''); // =>
@param path
filename or file descriptor
function
readFileSync(path:
PathOrFileDescriptor,options: BufferEncoding | { encoding: BufferEncoding; flag: string }): string;
Synchronously reads the entire contents of a file.
@param path
A path to a file. If a URL is provided, it must use the file: protocol. If a file descriptor is provided, the underlying file will not be closed automatically.
@param options
Either the encoding for the result, or an object that contains the encoding and an optional flag. If a flag is not provided, it defaults to 'r'.
function
readFileSync(path:
PathOrFileDescriptor,options?: null | BufferEncoding |
ObjectEncodingOptions & { flag: string }): string | NonSharedBuffer;
Synchronously reads the entire contents of a file.
@param path
A path to a file. If a URL is provided, it must use the file: protocol. If a file descriptor is provided, the underlying file will not be closed automatically.
@param options
Either the encoding for the result, or an object that contains the encoding and an optional flag. If a flag is not provided, it defaults to 'r'.
Referenced typestype
PathOrFileDescriptor =
PathLike | numberinterface
ObjectEncodingOptionsencoding?: null | BufferEncoding
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →