2
JavaScript fs.readFile function
ajayprashar (1)

Hi,
My name is Ajay and I am new to JavaScript. I have a question I was hoping you could help me with:

How do I access the function 'fs.readFile' from within node within repl.it?

import fs from 'fs';

let ourStuff = fs.readFile('G:\DATA\git\ipromise\ipromise.txt','utf8', callback);
console.log(ourStuff);

Thank you,
Ajay

You are viewing a single comment. View All
Answered by eankeen (528) [earned 5 cycles]
View Answer
1
ajayprashar (1)

@eankeen In appreciation of your reply, I thought I would provide an update.

As far as error messages go I adjusted my simple code as follows:

const fs = require('fs');

let ourStuff = fs.readFile('G:\\DATA\\git\\ipromise\\ipromise.txt','utf8', (err, data) => {
		if (err) throw err; 
	
		// Converting Raw Buffer to text 
		// data using tostring function. 
		console.log('#################'); 
		console.log(data); 
	})

It occurred to me that perhaps the backslashes were being misinterpreted as escape keys or escape sequences, so I doubled them up as I do in linux configuration files. This adjustment rid me of all the error messages. Partial success!!!

However, the code does seem to run locally using Node with good output, but it runs successfully with NO output on repl.it.

Should I assume that this is a security related issue?
-Ajay