Skip to content

Commit 8a0fa9f

Browse files
committed
task 2 done and task 1 fixed path for file
1 parent da52fa6 commit 8a0fa9f

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

database/people.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

database/task-1/people.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Marcia, Gutmann, qutelicoz, [email protected], February 11

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
import { faker } from "@faker-js/faker";
2-
import c from "chalk";

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"private": "true",
77
"scripts": {
8-
"task1": "node task-1.js",
8+
"task1": "node ./src/task-1.js",
9+
"task2": "node ./src/task-2.js",
910
"test": "echo \"Error: no test specified\" && exit 1"
1011
},
1112
"type": "module",

src/task-1.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { generateRandomUserDataString as newEntry } from "./generateRandomUserDataString.js";
2-
import fs, { appendFile } from "node:fs/promises";
2+
import { appendFile, mkdir } from "node:fs/promises";
33

44
const fileName = "people.txt";
5-
const dirPath = new URL("./../database/task-1", import.meta.url);
6-
await fs.mkdir(dirPath, { recursive: true });
5+
const dirPath = new URL("./../database/task-1", import.meta.url).pathname;
6+
await mkdir(dirPath, { recursive: true });
77
try {
8-
const entry = newEntry();
9-
await appendFile(`${dirPath}${fileName}`, entry); ///kelias ne nuo sito failo, bet nuo project rooto??...
8+
await appendFile(`${dirPath}/${fileName}`, newEntry()); ///kelias ne nuo sito failo, bet nuo project rooto??...
109
} catch (err) {
1110
console.error(err);
1211
}

src/task-2.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { generateRandomUserDataString as newEntry } from "./generateRandomUserDataString.js";
2+
import c from "chalk";
3+
import { appendFile, mkdir } from "node:fs/promises";
4+
import readline from "node:readline/promises";
5+
const fileName = "people.txt";
6+
const dirPath = new URL("./../database/task-1", import.meta.url).pathname;
7+
8+
console.log(c.yellow.bold("LOGIN: "));
9+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
10+
let login = await rl.question(c.bgBlue.bold("username:") + " ");
11+
let password = await rl.question(c.bgBlue.bold("password:") + " ");
12+
13+
if (login.trim() !== "admin" || password.trim() !== "1234") {
14+
console.log(c.red("Neteisingi prisijungimo duomenys"));
15+
rl.close();
16+
} else {
17+
await mkdir(dirPath, { recursive: true });
18+
try {
19+
await appendFile(`${dirPath}/${fileName}`, newEntry()); ///kelias ne nuo sito failo, bet nuo project rooto??...
20+
console.log(c.green("Duomenys faile sėkmingai išsaugoti"));
21+
} catch (err) {
22+
console.error(err);
23+
} finally {
24+
rl.close();
25+
}
26+
}

0 commit comments

Comments
 (0)