I am attempting to convert a text file (on my machine) into a string. What is the best/simplest way to do this? I am looking for a basic function that would look like this:
function fileToString(filepath) {
//this returns a string with the contents of the file
}
How should I do this?
EDIT: I now know that there is another question that asks this, but I didn't understand that question so I asked it in different words.
You need node.js for that and this code:
const fs = require('fs')
const fileContents = fs.readFileSync('./myFile').toString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With