Answers for "fs javascript read file"

2

read a file nodejs

const fs = require('fs');

fs.readFile('my-file.txt', 'utf8', function(err, data) {
    if (err) throw err;
    console.log(data);
});
Posted by: Guest on April-17-2021
1

read file in nodejs using fs

let myFile = "./myText.txt";
const fs = require("fs");
		
app.all('/test', async (req, res) => {
	try {
		const readData = fs.readFileSync(myFile, 'utf8');
		if (readData) {
			res.send(readData)
		}
	} catch (error) {
		res.send("something is wrong", error)
	}
})
Posted by: Guest on January-07-2021
1

javascript fs read

fs.readFile('/etc/passwd', (err, data) => {
  if (err) throw err;
  console.log(data);
});
Posted by: Guest on April-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language