Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 days 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 (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-04T05:51:52.000Z (9 months ago)
- Last Synced: 2024-12-13T04:13:28.555Z (17 days 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: 2
- Watchers: 3
- 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 [email protected]: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)