1/*
2 This code comes from Vincent Lab
3 And it has a video version linked here: https://www.youtube.com/watch?v=fy2RF9JR1BI
4*/
5
6// Import dependencies
7const fs = require("fs");
8
9// Read the text file and split it on new lines
10const lines = fs.readFileSync("users.txt").toString().split("\r\n");
11
12// All of the parse users
13let users = [];
14
15// For each user in text file
16for (let index = 0; index < lines.length; index+=6) {
17
18 // Extract the user information out of the text file
19 users.push({
20 fullName: lines[index],
21 address: lines[index + 1] + lines[index + 2],
22 phone: lines[index + 3],
23 emailAddress: lines[index + 4]
24 });
25
26}
27
28// Save the extracted information to a json file
29fs.writeFileSync("users.json",JSON.stringify(users));