JavaScript fs.readFile
ajayprashar (1)

Hi.

My name is Ajay and I am learning JavaScript using Repl.it.

When I use the code below I receive the error that 'fs.readFile' is NOT a function. Does anyone know how to use this function within repl.it?

import fs from 'fs';

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

https://repl.it/@ajayprashar/iPromise

You are viewing a single comment. View All
ajayprashar (1)

@TheDrone7 Thank you for your assistance. I did try what you mentioned but it still errors for me:

node v10.15.2 linux/amd64
   
evalmachine.<anonymous>:1
import fs from 'fs';
       ^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInContext (vm.js:284:10)
    at evaluate (/run_dir/repl.js:133:14)
    at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
    at ReadStream.emit (events.js:189:13)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at ReadStream.Readable.push (_stream_readable.js:220:10)
    at lazyFs.read (internal/fs/streams.js:181:12)