# filendir

> Filendir allows you to write a file and create the directories found in its path if needed.

Latest version **2.0.1** (published 2022-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install filendir
pnpm add filendir
yarn add filendir
bun add filendir
```

## 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 | 2.0.1 |
| Published | 2022-04-29 |
| First published | 2014-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Kevin Purnelle |
| Maintainers | aodev |
| Keywords | write, file, create, directory, mkdirp |

## Links

- npm: https://www.npmjs.com/package/filendir
- Repository: https://github.com/AoDev/Filendir
- Homepage: https://github.com/AoDev/Filendir#readme
- Issues: https://github.com/AoDev/Filendir/issues
- npm.io page: https://npm.io/package/filendir

## Dependencies (1)

- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4

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

- 2.0.1 (latest) — 2022-04-29
- 2.0.0 — 2020-05-21
- 1.0.2 — 2018-07-18
- 1.0.1 — 2018-02-28
- 1.0.0 — 2015-09-25
- 0.0.1 — 2014-05-10

## README

# Filendir

Write a file given a full path. Create the missing directories if necessary.

---

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![Build Status](https://app.travis-ci.com/AoDev/Filendir.svg?branch=master)](https://app.travis-ci.com/AoDev/Filendir)
![Node.js >= 10](https://img.shields.io/badge/nodejs-%3E%3D%2010-brightgreen)

## API

Filendir exposes an asynchronous and a synchronous write method.

It also exposes `mkdirp` to create directories only, if you need it.

## filendir versions node support

- 1.x for nodejs **v4** to **v9**
- 2.x for nodejs **v10** to **now**

### Synchronous write

- **filendir.ws** (shorthand)
- **filendir.writeFileSync**

Apart from creating the missing directories,
it has the same behaviour and interface than node `fs.writeFileSync`.

```js
// signature
filendir.writeFileSync(filename, data[, options])
```

[See fs.writeFileSync in Node.js site](https://nodejs.org/api/fs.html#fs_fs_writefilesync_filename_data_options)

**Example**

```js
var path = require('path')
var filendir = require('filendir')
var filename = path.join('let', 's', 'nest', 'some', 'directories', 'myfile.txt')
var content = 'Hello World'

filendir.ws(filename, content)
```

### Asynchronous write

- **filendir.wa** (shorthand)
- **filendir.writeFile**

Apart from creating the missing directories,
it has the same behaviour and interface than node `fs.writeFile`.

**Extra from fs.writefile**: you can use promises

```js
// callback use
filendir.writeFile(filename, data[, options], callback)
```

```js
// with promise
await filendir.writeFile(filename, data[, options])
```

[See fs.writeFile in Node.js site](https://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback)

**Example**

```js
var path = require('path')
var filendir = require('filendir')
var filename = path.join('let', 's', 'nest', 'some', 'directories', 'myfile.txt')
var content = 'Hello World'

filendir.wa(filename, content, function (err) {
  if (!err) {
    console.log('File written!')
  }
})
```

### filendir.mkdirp

Credits to Substack. Would have been harder to do this without it.

See https://www.npmjs.org/package/mkdirp

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