-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (15 loc) · 788 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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