# write-yaml-file

> Stringify and write YAML to a file atomically

Latest version **6.0.0** (published 2026-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install write-yaml-file
pnpm add write-yaml-file
yarn add write-yaml-file
bun add write-yaml-file
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2026-03-11 |
| First published | 2017-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.13 |
| Dependencies | 2 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 104 |
| Author | Zoltan Kochan |
| Maintainers | zkochan |
| Keywords | write, yaml, stringify, file, fs, graceful, stable, atomic, atomically |

## Links

- npm: https://www.npmjs.com/package/write-yaml-file
- Repository: https://github.com/zkochan/packages/tree/main/write-yaml-file
- Homepage: https://github.com/zkochan/packages/tree/main/write-yaml-file#readme
- npm.io page: https://npm.io/package/write-yaml-file

## Dependencies (2)

- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.1
- [write-file-atomic](https://npm.io/package/write-file-atomic.md) ^7.0.1

## 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

- 6.0.0 (latest) — 2026-03-11
- 4.2.0 (next) — 2021-02-11
- 4.0.0 (pnpm-temp) — 2020-03-26
- 5.0.0 — 2023-04-27
- 4.1.3 — 2021-01-09
- 4.1.2 — 2021-01-09
- 4.1.1 — 2020-11-01
- 4.1.0 — 2020-04-25
- 3.0.1 — 2019-05-30
- 3.0.0 — 2019-05-29
- 2.1.0 — 2019-05-29
- 2.0.0 — 2018-10-28
- 1.0.1 — 2018-03-17
- 1.0.0 — 2017-02-12
- 0.0.0 — 2017-02-11

## README

# write-yaml-file

> Stringify and write YAML to a file atomically

Creates directories for you as needed.

## Installation

```
<pnpm|yarn|npm> add write-yaml-file
```

## Usage

```js
const writeYamlFile = require('write-yaml-file')

writeYamlFile('foo.yaml', {foo: true}).then(() => {
  console.log('done')
})
```

## API

### `writeYamlFile(filepath, data, [options])`

Returns a promise.

### `writeYamlFile.sync(filepath, data, [options])`

#### `options`

Same options that can be passed in to [js-yaml](https://www.npmjs.com/package/js-yaml#safedump-object---options-)

##### mode

Type: `number`
Default `438` *(0666 in octal)*

[Mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file.

#### makeDir

Type: `boolean`
Default: `true`

Creates the directory to which the YAML file is written.

## Related

- [load-yaml-file](https://github.com/LinusU/load-yaml-file) - Read and parse a YAML file

## License

[MIT](LICENSE) © [Zoltan Kochan](https://www.kochan.io)

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