Skip to content

Instantly share code, notes, and snippets.

@Mansh05
Created June 9, 2018 10:24
Show Gist options
  • Select an option

  • Save Mansh05/54ea3ca5d051dec8eafbc0582459a594 to your computer and use it in GitHub Desktop.

Select an option

Save Mansh05/54ea3ca5d051dec8eafbc0582459a594 to your computer and use it in GitHub Desktop.

Revisions

  1. Mansh05 created this gist Jun 9, 2018.
    28 changes: 28 additions & 0 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    let fs = require('fs');

    let checkJson = (path) => {
    fs.readdir(path, (err, files) => {
    files.forEach(file => {
    if (fs.lstatSync(`${path}/${file}`).isDirectory()) {
    checkJson(`${path}/${file}`)
    } else {
    readFile(`${path}/${file}`);
    }
    });
    });
    }

    let readFile = (path) => {
    let aa = fs.createReadStream(path, 'utf8');
    aa.on('data', (chunk) => {
    try {
    JSON.parse(chunk);
    // console.log(JSON.parse(chunk));
    } catch (e) {
    console.log('There is an error in' + path);
    process.exit(1);
    }
    });
    }

    checkJson('./demo');