https://github.com/fibo/read-file-utf8
reads content from file using utf-8 encoding
https://github.com/fibo/read-file-utf8
promise readfile utf8
Last synced: 7 days ago
JSON representation
reads content from file using utf-8 encoding
- Host: GitHub
- URL: https://github.com/fibo/read-file-utf8
- Owner: fibo
- Created: 2016-04-19T09:40:27.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2025-12-16T07:50:08.000Z (6 months ago)
- Last Synced: 2026-04-27T00:23:35.367Z (2 months ago)
- Topics: promise, readfile, utf8
- Language: JavaScript
- Homepage:
- Size: 52.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# read-file-utf8
> reads content from file using utf-8 encoding, also imports JSON files easily
## Installation
With [npm](https://npmjs.org/) do
```sh
npm install read-file-utf8
```
## Usage
`read(filePath: string): Promise`
Read from a text file.
```js
import read from 'read-file-utf8';
const filePath = 'path/to/file.txt';
try {
// Read file content.
const content = await read(filePath)
console.log(content)
} catch (error) {
// In case you do not have permissions,
// you may want to handle it here.
console.error(error)
}
```
Read from a JSON file: given the `.json` extension then `JSON.parse` is used to parse it.
```js
// Read version from package.json file.
const { version } = await read('./package.json');
console.log(version)
```
If you are using TypeScript can provide the type of your JSON.
```ts
const { version } = await read<{ version: string }>('./package.json');
```
> [!WARNING]
> No validation is done on the JSON content.
## See also
- [write-file-utf8](https://github.com/fibo/write-file-utf8)
## License
[MIT](https://fibo.github.io/mit-license/)