1// load fs
2const fs = require("fs");
3// read the file
4const content = fs.readFileSync("./my_file.txt");
5// print it
6console.log(content.toString());
1const fs = require('fs');
2
3fs.readFile('my-file.txt', 'utf8', function(err, data) {
4 if (err) throw err;
5 console.log(data);
6});
1let myFile = "./myText.txt";
2const fs = require("fs");
3
4app.all('/test', async (req, res) => {
5 try {
6 const readData = fs.readFileSync(myFile, 'utf8');
7 if (readData) {
8 res.send(readData)
9 }
10 } catch (error) {
11 res.send("something is wrong", error)
12 }
13})
1fs.readFile('filename', function read(err, data) {
2 if (err) {
3 throw err;
4 }
5 var content = data;
6
7 console.log(content);
8
9});
1fs = require('fs')
2fs.readFile('/etc/hosts', 'utf8', function (err,data) {
3 if (err) {
4 return console.log(err);
5 }
6 console.log(data);
7});