Skip to content

Returns file content as a UTF-8 string. Returns null if file does not exist (or is a directory) instead of throwing an Error.

License

Notifications You must be signed in to change notification settings

Jaid/read-file-string

Repository files navigation

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

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

read-file-string on Yarn

yarn add read-file-string@^1.1.2

@jaid/read-file-string on GitHub Packages
(if configured properly)

npm install --save @jaid/read-file-string@^1.1.2

Example

import readFileString from "read-file-string"

readFileString("./existingFile.txt").then(result => {

})

readFileString("./doesNotExist.txt").then(result2 => {

})

Variable result will be:

"the file contents"

Variable result2 will be:

null

Development

Setting up:

git clone git@github.com:jaid/read-file-string.git
cd read-file-string
npm install

Testing:

npm run test:dev

Testing in production environment:

npm run test

License

MIT License
Copyright © 2021, Jaid <jaid.jsx@gmail.com> (https://github.com/jaid)