//if not global, you have to introduce FS membersConstFS = require ("FS");//a Fs.readfile method is provided in the FS core module to read the files in the specified directory//Fs.resdfile of three parameters//1, read the path to the file//2. Read the encoding format of the file//3, when the file reads complete, call this callback callback function to read the result of the file//first argument text Error object The second argument is the result of a successful read//fs.readfile ('./http/111.txt ', ' utf-8 ', function (error,data) {//Console.log (Error); //If err is null it means that the read was successful and there was no error//console.log (data);//If you do not give the second parameter [read file encoding format] It will be output in beffer format// });Fs.readfile ("./http/111.txt","Utf-8", function (error, data) {//Console.log (Error); //If err is null it means that the read was successful and there was no error//console.log (data);//If you do not give the second parameter [read file encoding format] It will be output in beffer format//use error to determine if the file was read successfully if(Error)returnConsole.log ("failed to read file, content is"+error.message); Console.log ("read file successfully, content is"+( data);});
Read file operation with NODEJS implementation