In-memory filesystem with Node.js fs-compatible API
npm install @jsonjoy.com/fs-nodeIn-memory filesystem with Node.js fs-compatible API.
``bash`
npm install @jsonjoy.com/fs-node
`ts
import { Volume } from '@jsonjoy.com/fs-node';
const vol = new Volume();
vol.writeFileSync('/hello.txt', 'Hello, World!');
console.log(vol.readFileSync('/hello.txt', 'utf8')); // Hello, World!
`
`ts
import { Volume } from '@jsonjoy.com/fs-node';
const vol = Volume.fromJSON({
'/app/index.js': 'console.log("Hello");',
'/app/package.json': '{"name": "app"}',
});
console.log(vol.readdirSync('/app')); // ['index.js', 'package.json']
`
The Volume class implements Node.js fs module's synchronous and callback APIs:
- readFile, readFileSyncwriteFile
- , writeFileSyncmkdir
- , mkdirSyncreaddir
- , readdirSyncstat
- , statSyncunlink
- , unlinkSync
- ... and many more
It also exposes a promises property for the Promise-based API:
`ts``
const data = await vol.promises.readFile('/hello.txt', 'utf8');
Apache-2.0