Use path and fs:
const fs = require("fs"); const pth = require("path");
Sync:
let data = fs.readFileSync(pth.join(__dirname,"file.txt")); console.log(data + "");
A-Sync:
fs.readFile(pth.join(__dirname,"file.txt"), (err, data) => { console.log(data + ""); });
And that; If you need to read the file continuously and send it to the client and the file size is not large, you may be able to keep a copy of it:
const exp = require("express"); const app = exp(); const fs = require("fs"); const pth = require("path"); let file = ""; app.get("/file", (q, r) => { if (file === "") file = fs.readFileSync(pth.join(__dirname,"file.txt")) + ""; r.writeHead(200, { "Content-Type": "text/plain" }); r.write(file); r.end(); });