File Handling Toolkit is a Node.js package that provides utility functions for handling files, including reading and writing text files, as well as reading CSV files and converting them to arrays of objects.
You can install the File Handling Toolkit package via npm:
npm install file-handling-toolkit
const { readFile } = require('file-handling-toolkit');
readFile('example.txt')
.then(data => {
console.log('File content:', data);
})
.catch(error => {
console.error('Error reading file:', error);
});
const { writeFile } = require('file-handling-toolkit');
const data = 'Hello, world!';
writeFile('output.txt', data)
.then(() => {
console.log('Data written to file successfully!');
})
.catch(error => {
console.error('Error writing to file:', error);
});
const { writeFile } = require('file-handling-toolkit');
const data = 'Appending this text.';
writeFile('output.txt', data, true)
.then(() => {
console.log('Data appended to file successfully!');
})
.catch(error => {
console.error('Error appending to file:', error);
});
const { readCsvToArray } = require('file-handling-toolkit');
readCsvToArray('example.csv')
.then(data => {
console.log('CSV Data:', data);
})
.catch(error => {
console.error('Error reading CSV file:', error);
});
Reads the contents of a file and returns a Promise that resolves with the file content as a string.
-
filePath
: Path to the file to be read.
Writes data to a file and returns a Promise that resolves when the operation completes successfully.
-
filePath
: Path to the file to write. -
data
: Data to be written to the file. -
append
(optional): Iftrue
, appends data to the file instead of overwriting it. Defaults tofalse
.
Reads a CSV file and returns a Promise that resolves with the content of the CSV file as an array of objects.
-
filePath
: Path to the CSV file to be read.
This project is licensed under the MIT License - see the LICENSE file for details.
- Append to a File Feature: Added an example usage for appending data to an existing file.
-
API Reference Update: Updated the
writeFile
function in the API reference to include the new optionalappend
parameter.
This updated README.md
provides clear instructions and examples for users on how to use the new appending feature along with the existing file read, write, and CSV read features.