fork download
  1. const fs = require('fs');
  2.  
  3. function readFiles(file1, file2, callback) {
  4. fs.readFile(file1, 'utf8', (err, data1) => {
  5. if (err) {
  6. console.log('Error reading file1:', err);
  7. }
  8. fs.readFile(file2, 'utf8', (err, data2) => {
  9. if (err) {
  10. console.log('Error reading file2:', err);
  11. }
  12. callback(data1, data2);
  13. });
  14. });
  15. }
  16.  
  17. readFiles('file1.txt', 'file2.txt', (data1, data2) => {
  18. console.log('File 1 Data:', data1);
  19. console.log('File 2 Data:', data2);
  20. });
  21.  
Success #stdin #stdout 0.1s 35752KB
stdin
Standard input is empty
stdout
Error reading file1: { [Error: ENOENT: no such file or directory, open 'file1.txt'] errno: -2, code: 'ENOENT', syscall: 'open', path: 'file1.txt' }
Error reading file2: { [Error: ENOENT: no such file or directory, open 'file2.txt'] errno: -2, code: 'ENOENT', syscall: 'open', path: 'file2.txt' }
File 1 Data: undefined
File 2 Data: undefined