javascript - Error : Cannot read property 'forEach' of undefined -


i try read unformatted document rewrite in format when execute following code got error cannot read property 'foreach' of undefined (full error below). don't understand why error happening , how resolve it.

code

const testfolder = '/zip_file\ /sit1_wave2_settlement_afx_formula\ \(1\)/data_dictionary/cm.173/';  var fs = require('fs'); var formatedcode = []; fs.readdir(testfolder, (err, files) => {      files.foreach(file => {       console.log(file);       var array = fs.readfilesync(testfolder + file).tostring().split("\n");       //console.log("\n\n\n",array);       var wstream = fs.createwritestream(file);        (i in array) {         var xml = array[i],         pp_xml = require('../pretty-data').pd.xml(xml);         formatedcode.push(pp_xml);       }        (look in formatedcode) {         var wstream = fs.createwritestream(file);          wstream.on('finish', function () {           console.log('file has been written');         });          wstream.write(formatedcode[look]);         wstream.end();       }   }); }) 

error

files.foreach(file => {^  typeerror: cannot read property 'foreach' of undefined   @ fs.readdir (c:\users\manoj kumar\downloads\pretty-data\pretty-data\findingxml.js:5:6)   @ fsreqwrap.oncomplete (fs.js:123:15) 

i have done modifications code. there other things need careful wstream defined multiple times may cause unexpected results.

regarding issue please try below;

files.foreach((file) =>  {     console.log(file); 

for convenience check out full code block;

const testfolder = '/zip_file\ /sit1_wave2_settlement_afx_formula\ \(1\)/data_dictionary/cm.173/';  var fs = require('fs'); var formatedcode = []; fs.readdir(testfolder, (err, files) => {      files.foreach((file) =>      {         console.log(file);          var array = fs.readfilesync(testfolder + file).tostring().split("\n");         //console.log("\n\n\n",array);          var wstream = fs.createwritestream(file);         (var in array) {             var xml = array[i],                  pp_xml = require('../pretty-data').pd.xml(xml);             formatedcode.push(pp_xml);          }         (var in formatedcode) {             wstream = fs.createwritestream(file);             wstream.on('finish', function () {                 console.log('file has been written');             });             wstream.write(formatedcode[look]);             wstream.end();         }     }); }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -