# fs-mode

> Provides async and sync fs methods with identical APIs

Latest version **1.0.1** (published 2014-10-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install fs-mode
pnpm add fs-mode
yarn add fs-mode
bun add fs-mode
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-10-02 |
| First published | 2014-10-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Elan Shanker |
| Maintainers | es128 |
| Keywords | fs, mode, async, sync, file |

## Links

- npm: https://www.npmjs.com/package/fs-mode
- Repository: https://github.com/es128/fs-mode
- Issues: https://github.com/es128/fs-mode/issues
- npm.io page: https://npm.io/package/fs-mode

## Dependencies (1)

- [cbify](https://npm.io/package/cbify.md) ^1.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-10-02
- 1.0.0 — 2014-10-01

## README

# fs-mode

A drop-in replacement for Node's native `fs` module which adds `fs.Async` and
`fs.Sync` namespaces with identical method names and APIs. So
`fs.Async.readFile` is the same as `fs.readFile`, and `fs.Sync.readFile` is a
wrapped version of `fs.readFileSync` which passes the result to a callback
instead of just returning it.

## Installation

`npm install --save fs-mode`

## Usage

```js
var fs = require('fs-mode');

function myModule (fs, otherArg, callback) {
	// normal fs stuff using async methods
	fs.readFile('myFile', function (err, data) {
		if (err) return callback(err);
		var result = doSomethingTo(data);
		callback(null, result);
	});
}

module.exports = {
	myModule: myModule.bind(null, fs.Async),
	myModuleSync: function (otherArg) {
		var result;
		myModule(fs.Sync, otherArg, function (err, data) {
			if (err) throw err;
			result = data;
		});
		return result;
	}
}
```

As you can see, this makes it pretty easy to adapt an existing async module
using fs methods to also provide a sync option. For a real-world example of
this type of conversion, see https://github.com/es128/progeny/commit/6685987033036f9c6c1dc5afcc69268221681538

#### Use with other fs replacements

Such as graceful-fs or fs-extra

```js
var fs = require('fs-mode')('graceful-fs');
```

## License

[ISC](https://raw.github.com/es128/fs-mode/master/LICENSE)

---
_Source: https://npm.io/package/fs-mode · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
