Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

# read-file-string

License Sponsor read-file-string
Build status Commits since v1.1.2 Last commit Issues
Latest version on npm Dependents Downloads

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

read-file-string on npm

```bash
npm install --save read-file-string@^1.1.2
```

read-file-string on Yarn

```bash
yarn add read-file-string@^1.1.2
```

@jaid/read-file-string on GitHub Packages
(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)