fs.readFileSync(path[, options])


返回 path 的内容。

【Returns the contents of the path.】

有关详细信息,请参阅此 API 异步版本的文档:fs.readFile()

【For detailed information, see the documentation of the asynchronous version of this API: fs.readFile().】

如果指定了 encoding 选项,则该函数返回一个字符串。否则,它返回一个缓冲区。

【If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.】

类似于 fs.readFile(),当路径是目录时,fs.readFileSync() 的行为取决于平台。

【Similar to fs.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('<directory>');
// => [Error: EISDIR: illegal operation on a directory, read <directory>]

//  FreeBSD
readFileSync('<directory>'); // => <data>