Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

read file node

// load fs
const fs = require("fs");
// read the file
const content = fs.readFileSync("./my_file.txt");
// print it
console.log(content.toString());
Comment

read a file nodejs

const fs = require('fs');

fs.readFile('my-file.txt', 'utf8', function(err, data) {
    if (err) throw err;
    console.log(data);
});
Comment

Reading files with Node.js

JS
copy
const fs = require('fs')

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err)
    return
  }
  console.log(data)
})
Comment

readfile nodejs

const fs = require('fs')

try {
  const data = fs.readFileSync('/Users/joe/test.txt', 'utf8')
  console.log(data)
} catch (err) {
  console.error(err)
}
Comment

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)
	}
})
Comment

nodejs open file

fs = require('fs')
fs.readFile('/etc/hosts', 'utf8', function (err,data) {
  if (err) {
    return console.log(err);
  }
  console.log(data);
});
Comment

read files in node js

const fs = require("fs");
const text = fs.readFileSync("dele.txt", "utf-8")
console.log("The content of the file is")
console.log(text);
Comment

how to read files in node

var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
  fs.readFile('index.html', function(err, data) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });
}).listen(8080);
Comment

PREVIOUS NEXT
Code Example
Javascript :: moment get start of week in datetime 
Javascript :: javascript kill ajax request 
Javascript :: bootstrap datepicker options 
Javascript :: js data object length 
Javascript :: How to make blinking/flashing text with jQuery 
Javascript :: how to change materil ui divider coloer 
Javascript :: toggle boolean js 
Javascript :: jquery change page on click 
Javascript :: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html" 
Javascript :: nodejs buffer.from base64 
Javascript :: angular bind style value 
Javascript :: javascript canvas to image 
Javascript :: javascript override shortcut 
Javascript :: javascript get date 
Javascript :: loading image in react js 
Javascript :: find highest and lowest number string javascript 
Javascript :: input type styled components 
Javascript :: how to set input date to today date on initialization 
Javascript :: wordpress not loading jquery 
Javascript :: replace componentwillmount with hooks 
Javascript :: find last element in array nodejs 
Javascript :: npm execute script with nodemon 
Javascript :: remove classname to node 
Javascript :: javascript 1 line if 
Javascript :: js pad array 
Javascript :: anime js link 
Javascript :: check every value in array javascript 
Javascript :: javascript type casting int 
Javascript :: number_format in jquery 
Javascript :: To get thumbnail image from video file 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =