# read-utf8-file

> Read the contents of a UTF-8 file

Latest version **3.0.0** (published 2019-06-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install read-utf8-file
pnpm add read-utf8-file
yarn add read-utf8-file
bun add read-utf8-file
```

## 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 | 3.0.0 |
| Published | 2019-06-04 |
| First published | 2016-10-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Watanabe Shinnosuke |
| Maintainers | shinnn |
| Keywords | read, file, fs, content, data, utf8, utf-8, load, promise, async, asynchronous |

## Links

- npm: https://www.npmjs.com/package/read-utf8-file
- Repository: https://github.com/shinnn/read-utf8-file
- Homepage: https://github.com/shinnn/read-utf8-file#readme
- Issues: https://github.com/shinnn/read-utf8-file/issues
- npm.io page: https://npm.io/package/read-utf8-file

## Dependencies (3)

- [is-utf8](https://npm.io/package/is-utf8.md) ^0.2.1
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^2.0.0
- [inspect-with-kind](https://npm.io/package/inspect-with-kind.md) ^1.0.5

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

- 3.0.0 (latest) — 2019-06-04
- 3.0.0-0 — 2019-05-30
- 2.0.2 — 2019-05-28
- 2.0.1 — 2019-05-27
- 2.0.0 — 2018-01-18
- 2.0.0-0 — 2018-01-15
- 1.0.4 — 2018-01-10
- 1.0.3 — 2018-01-07
- 1.0.2 — 2018-01-04
- 1.0.1 — 2017-04-11
- 1.0.0 — 2016-11-16
- 0.4.0 — 2016-11-11
- 0.3.1 — 2016-11-09
- 0.3.0 — 2016-11-07
- 0.2.1 — 2016-11-07
- … 3 more at https://npm.io/package/read-utf8-file/versions

## README

# read-utf8-file

[![npm version](https://img.shields.io/npm/v/read-utf8-file.svg)](https://www.npmjs.com/package/read-utf8-file)
[![Build Status](https://travis-ci.com/shinnn/read-utf8-file.svg?branch=master)](https://travis-ci.com/shinnn/read-utf8-file)
[![codecov](https://codecov.io/gh/shinnn/read-utf8-file/branch/master/graph/badge.svg)](https://codecov.io/gh/shinnn/read-utf8-file)

A [Node.js](https://nodejs.org/) module to read the contents of a UTF-8 file

```javascript
const readUtf8File = require('read-utf8-file');

(async () => {
  const contents = await readUtf8File('/path/to/utf8-file.txt');
  //=> 'string of file contents'
})();
```

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

```
npm install read-utf8-file
```

## API

```javascript
const readUtf8File = require('read-utf8-file');
```

### readUtf8File(*filePath* [, *options*])

*filePath*: `string | Buffer | Uint8Array | URL` (file path)  
*options*: `Object` ([`fs.promises.readFile()`](https://nodejs.org/api/fs.html#fs_fspromises_readfile_path_options) options except for `encoding`)  
Return: `Promise<string>` (entire file contents except for [BOM](https://unicode.org/faq/utf_bom.html))

```javascript
// file-with-bom.txt: '\uFEFFabc'

(async () => {
  await readUtf8File('file-with-bom.txt'); //=> 'abc'
})();
```

If the file is not [UTF-8](https://tools.ietf.org/html/rfc3629) encoded, the `Promise` will be rejected. So this module is more suitable than built-in `fs.readFile()` for the case when the program doesn't support non-UTF-8 files.

```javascript
(async () => {
  await readUtf8File('/path/to/non-utf8-file');
  // rejects with Error: Expected a UTF-8 file, but the file at '/path/to/non-utf8-file' is not UTF-8 encoded.
})();
```

## License

[ISC License](./LICENSE) © 2017 - 2019 Watanabe Shinnosuke

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