# fs-sync

> synchronous fs with more fun

Latest version **1.0.7** (published 2025-08-14) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

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

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2025-08-14 |
| First published | 2013-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | kael |
| Maintainers | kael |
| Keywords | fs, fs-sync, sync, synchronous fs, copy, mkdir, mkdirp, write, read, readJSON, isDir, isFile, isLink, exists, grunt file, delete, expand, contain |

## Links

- npm: https://www.npmjs.com/package/fs-sync
- Repository: https://github.com/kaelzhang/node-fs-sync
- Homepage: https://github.com/kaelzhang/node-fs-sync#readme
- Issues: https://github.com/kaelzhang/node-fs-sync/issues
- npm.io page: https://npm.io/package/fs-sync

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^7.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.16.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [rimraf](https://npm.io/package/rimraf.md) ^2.1.4
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.4.13

## 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.7 (latest) — 2025-08-14
- 1.0.6 — 2018-08-17
- 1.0.5 — 2018-08-17
- 1.0.4 — 2017-02-24
- 1.0.3 — 2016-10-02
- 1.0.2 — 2016-02-15
- 1.0.1 — 2015-10-23
- 1.0.0 — 2015-10-22
- 0.2.6 — 2015-08-04
- 0.2.5 — 2014-07-28
- 0.2.4 — 2013-10-07
- 0.2.2 — 2013-09-26
- 0.2.1 — 2013-08-09
- 0.1.7 — 2013-08-03
- 0.1.6 — 2013-07-16
- … 5 more at https://npm.io/package/fs-sync/versions

## README

Maintenance for this project has been discontinued in favor of using [fs-extra](https://www.npmjs.com/package/fs-extra)

----

[![Build Status](https://travis-ci.org/kaelzhang/node-fs-sync.png?branch=master)](https://travis-ci.org/kaelzhang/node-fs-sync)

# fs-sync

> Synchronous fs with more fun

## Getting Started
This module is created for the favor of use of `fs.xxxSync`.

Once `fs-sync` is installed, you can use:

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

if(fs.exists('package.json')){
	var pkg = fs.readJSON('package.json');
}
```

## Methods

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

### fs.defaultEncoding
Type: `String`

Default value: `'utf-8'`

Global default encoding

```js
fs.defaultEncoding = 'utf-8'
```

### fs.copy(from, to, options)

Copy a file or a whole directory to the destination. During this, necessary directories will be created.

#### Syntax

```js
fs.copy(file, destpath, options);
fs.copy(dir, destpath, options);
```

#### file
Type: `String`

Path of file to be copied

#### dir
Type: `String`

Path of directory to be copied

#### options.force
Type: `Boolean`

Default value: `false`

By default, `fs.copy` will not override existed files, set `options.force` as `true` to override.


### fs.mkdir(path)

Commandline `mkdir` or `mkdir -p`


### fs.expand(patterns, options)

Like `grunt.file.expand`, but the sequence of the arguments is different


### fs.write(file, content, options)

#### options
Type: `Object`

The same as the `options` argument of [fs.writeFile](http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback)

### fs.read(file, options)
Read a file

#### options
Type: `Object`

The same as the `options` argument of [fs.writeFile](http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback), except:

#### options.encoding
Type: `String`

Default value: `fs.defaultEncoding`

### fs.readJSON(file, options)
Read a file as the JSON format, if the file content fails to be parsed as JSON, an error will be thrown.

### fs.remove()

Delete a file or a whole directory. It's a dangerous action, be careful.

Equivalent to `rm -rf`(remove a folder and all its contents) or `rm -f`(unlink a file)

#### Syntax

```js
fs.remove(file)
fs.remove(dir)
```

### fs.exists(...)

`arguments` will be called with `path.join`

### fs.isDir(path)

### fs.isFile(path)

### fs.isLink(path)

### fs.isPathAbsolute(path)

#### Returns `Boolean`

Whether the given `path` is an absolute path (starting with `'/'`)

### fs.doesPathContain(ancestor, path...)

```js
if(fs.doesPathContain(ancestor, path, path2)){
	console.log(path, 'and', path2, 'are inside', ancestor);
}
```

#### Returns `Boolean`

Whether path `ancestor` contains all `path`s after

#### ancestor `String`

Ancestor path

#### path `String`

The arguments of `fs.doesPathContain` could be more than 2.

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