https://github.com/jaid/read-file-string
Returns file content as a UTF-8 string. Returns null if file does not exist (or is a directory) instead of throwing an Error.
https://github.com/jaid/read-file-string
file filesystem lib library load-file loader promise read-file string util utility
Last synced: 4 months ago
JSON representation
Returns file content as a UTF-8 string. Returns null if file does not exist (or is a directory) instead of throwing an Error.
- Host: GitHub
- URL: https://github.com/jaid/read-file-string
- Owner: Jaid
- License: mit
- Created: 2019-12-19T20:18:37.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-04-04T05:51:52.000Z (about 2 years ago)
- Last Synced: 2025-10-23T20:01:53.683Z (8 months ago)
- Topics: file, filesystem, lib, library, load-file, loader, promise, read-file, string, util, utility
- Language: JavaScript
- Homepage: https://github.com/Jaid/read-file-string
- Size: 5.51 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license.txt
Awesome Lists containing this project
README
# read-file-string
**Returns file content as a UTF-8 string. Returns null if file does not exist (or is a directory) instead of throwing an Error.**
## Installation
```bash
npm install --save read-file-string@^1.1.2
```
```bash
yarn add read-file-string@^1.1.2
```
(if [configured properly](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages))
```bash
npm install --save @jaid/read-file-string@^1.1.2
```
## Example
```javascript
import readFileString from "read-file-string"
readFileString("./existingFile.txt").then(result => {
})
readFileString("./doesNotExist.txt").then(result2 => {
})
```
Variable `result` will be:
```javascript
"the file contents"
```
Variable `result2` will be:
```javascript
null
```
## Development
Setting up:
```bash
git clone git@github.com:jaid/read-file-string.git
cd read-file-string
npm install
```
Testing:
```bash
npm run test:dev
```
Testing in production environment:
```bash
npm run test
```
## License
[MIT License](https://raw.githubusercontent.com/jaid/read-file-string/master/license.txt)
Copyright © 2021, Jaid \ (https://github.com/jaid)