Helper functions to read files as text, JSON, and additional formats.
npm i node-read-file-helper
const { readFileAsTextSync } = require('node-read-file-helper');
const path = require('path');
const asString = readFileAsTextSync(path.resolve('./myFile.txt'));
▸ readFileAsJSON<T
>(path
): Promise
<T
>
Reads the file as JSON content asynchronously
export
Name | Description |
---|---|
T |
The JSON structure after parsing |
Name | Type | Description |
---|---|---|
path |
string |
The path to the file to read |
Promise
<T
>
Promise that will resolve to the parsed JSON
index.ts:61
▸ readFileAsJSONSync<T
>(path
): T
Reads the file as JSON content
export
Name | Description |
---|---|
T |
The JSON structure after parsing |
Name | Type | Description |
---|---|---|
path |
string |
The path to the file to read |
T
The parsed JSON
index.ts:49
▸ readFileAsText(path
): Promise
<string
>
Reads file as text asynchronously
export
Name | Type | Description |
---|---|---|
path |
string |
The path to the file to read |
Promise
<string
>
The file contents
index.ts:23
▸ readFileAsTextSync(path
): string
Reads a file as text
export
Name | Type | Description |
---|---|---|
path |
string |
The path to the file to read |
string
The file contents as text
index.ts:10