Answers for "fs file.filename"

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

node.js name of file

var path = require('path');
var scriptName = path.basename(__filename);
Posted by: Guest on November-10-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language