FileSystem implementation backed by node:fs.
import { NodeFS } from '@stackpress/lib';Use NodeFS when you want the library filesystem interface but your runtime is standard Node.js.
const fs = new NodeFS();You can inject a compatible node:fs object for testing.
| Name | Type | Notes |
|---|---|---|
fs |
typeof import('node:fs') |
Underlying Node filesystem module. |
| Method | Returns |
|---|---|
exists(path) |
Promise<boolean> |
readFile(path, encoding) |
Promise<string> |
realpath(path) |
Promise<string> |
stat(path) |
Promise<FileStat> |
writeFile(path, data) |
Promise<void> |
mkdir(path, options?) |
Promise<void> |
createReadStream(path) |
FileStream |
unlink(path) |
Promise<void> |
import { NodeFS } from '@stackpress/lib';
const fs = new NodeFS();
if (await fs.exists('./package.json')) {
const json = await fs.readFile('./package.json', 'utf8');
console.log(json.length);
}