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 (758) [earned 5 cycles]
View Answer
eankeen (758)

@ajayprashar Hmm. I would not. Oversimplifying, repl.it runs their Node processes on Linux. And Linux uses forward slashes. I would consider using path.join() to ensure that it works both on your Windows machine and on replit. Something kind of like path.join(__dirname, 'ipromise.txt') instead of G:\\DATA...ipromise.txt.

To do this you need to import the path module

let path = require('path');

:)