-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
End of Lesson (Fakerjs + fs Read and Write)
- Loading branch information
0 parents
commit c6771df
Showing
4,518 changed files
with
24,525 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"_id":"f0beaf53-1a36-41c1-aa9c-6d9dd1e96980","name":"Gorgeous Gloves","description":"Andy shoes are designed to keeping in mind durability as well as trends, the most stylish range of shoes & sandals","brand":"Bahringer Inc","price":"$71.00","currency":"USD","inStock":false,"attributes":{"material":"Concrete","color":"orchid"}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//// Here will will write our File System Reading and Writing Functionality | ||
|
||
|
||
const fs = require("node:fs") | ||
|
||
|
||
// console.log("Node's File System: " , fs) | ||
// console.log("The Keys for the Node FS: ", Object.keys(fs)) | ||
|
||
// console.log("The Function readFileSync: ", Object.keys(fs.readFileSync)) | ||
// console.log("The Function writeFileSync: ", Object.keys(fs.writeFileSync)) | ||
|
||
|
||
//// readFileSync( "pathToTheFile", "howToReadTheFile") | ||
// const path = "./data" | ||
// const fileName = "products.json" | ||
|
||
// const collection = fs.readFileSync( `${path}/${fileName}` , "utf-8" ) | ||
|
||
// // condition ? trueAction : falseAction ~ Similar to if/else | ||
// // if (condition){ trueAction } else { falseAction } | ||
// const resultOfTernary = collection ? JSON.parse(collection) : []; | ||
|
||
// console.log( "Data from JSON File We Are Reading: " , resultOfTernary ) | ||
|
||
|
||
|
||
|
||
function readJSONFile(path, fileName){ | ||
|
||
const collection = fs.readFileSync( `${path}/${fileName}` , "utf-8" ) | ||
|
||
// is it an empty JSON File or NOT | ||
return collection ? JSON.parse(collection) : []; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
//// writeFileSync( "path" , data, { encoding: "utf-8" } ) | ||
|
||
|
||
function writeJSONFile(path, fileName, data){ | ||
|
||
data = JSON.stringify(data) | ||
|
||
fs.writeFileSync( `${path}/${fileName} `, data , { encoding: "utf-8" } ) | ||
|
||
} | ||
|
||
|
||
module.exports = { | ||
readJSONFile, | ||
writeJSONFile | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// console.log(":)") | ||
|
||
|
||
|
||
const { createRandomProduct } = require("./products.js") | ||
|
||
const { writeJSONFile, readJSONFile } = require("./helpers.js") | ||
|
||
|
||
//// run: function to run our entire Command Line App | ||
|
||
function run(){ | ||
|
||
console.log("Welcome to Our Products App!✨\n\n\n\n") | ||
|
||
// console.log( "Us Creating a Random Product (from the require): ", createRandomProduct() ) | ||
|
||
|
||
let productsData = readJSONFile( "./data" , "products.json" ) | ||
// if: file is empty -> Give us an empty array; Save it to our productsData variable | ||
// else: give us the existing array (collection); Save it to our productsData variable | ||
|
||
productsData.push( createRandomProduct() ) | ||
|
||
|
||
writeJSONFile( "./data" , "products.json", productsData ) | ||
|
||
|
||
} | ||
|
||
run() | ||
|
||
|
||
//////// process object + process.argv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.