Answers for "how to read files and store it in a variable nodejs"

3

node load file

const fs = require("fs");

// __dirname means relative to script. Use "./data.txt" if you want it relative to execution path.
fs.readFile(__dirname + "/data.txt", (error, data) => {
    if(error) {
        throw error;
    }
    console.log(data.toString());
});
Posted by: Guest on May-25-2020

Code answers related to "how to read files and store it in a variable nodejs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language