source: trip-planner-front/node_modules/fs-monkey/docs/api/patchFs.md@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 700 bytes
Line 
1# `patchFs(vol[, fs])`
2
3Rewrites Node's filesystem module `fs` with *fs-like* object.
4
5 - `vol` - fs-like object
6 - `fs` *(optional)* - a filesystem to patch, defaults to `require('fs')`
7
8```js
9import {patchFs} from 'fs-monkey';
10
11const myfs = {
12 readFileSync: () => 'hello world',
13};
14
15patchFs(myfs);
16console.log(require('fs').readFileSync('/foo/bar')); // hello world
17```
18
19You don't need to create *fs-like* objects yourself, use [`memfs`](https://github.com/streamich/memfs)
20to create a virtual filesystem for you:
21
22```js
23import {vol} from 'memfs';
24import {patchFs} from 'fs-monkey';
25
26vol.fromJSON({'/dir/foo': 'bar'});
27patchFs(vol);
28console.log(require('fs').readdirSync('/')); // [ 'dir' ]
29```
Note: See TracBrowser for help on using the repository browser.