All files / lib create-file.js

71.43% Statements 5/7
50% Branches 1/2
100% Functions 2/2
71.43% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 141x     1x   1x 1x       1x      
import fs from 'fs'
 
export function createFile(fileName, data) {
  const jsonContent = JSON.stringify(data, null, '\t');
 
  fs.writeFile(`${process.cwd()}/${fileName}`, jsonContent, 'utf8', function (err) {
    Iif (err) {
      console.log('\x1b[31m', "An error occured while writing JSON Object to File.");
      return console.log(err);
    }
    console.log('\x1b[32m', `Your file has been saved in ${process.cwd()}/output/${fileName}.`);
  });
}