-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (31 loc) · 879 Bytes
/
app.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
35
36
import fs from 'fs';
import inquirer from 'inquirer';
import qr from 'qr-image';
inquirer
.prompt([
{
type: 'input',
name: 'url',
message: 'Enter the URL:',
},
])
.then((answers) => {
const { url } = answers;
// Generate the QR code image
const qrCode = qr.image(url, { type: 'png' });
const qrImageFileName = 'qrcode.png';
qrCode.pipe(fs.createWriteStream(qrImageFileName));
// Save user input and QR code image URL to a text file
const textFileName = 'user_input.txt';
const fileContent = `User input URL: ${url}`;
fs.writeFile(textFileName, fileContent, (err) => {
if (err) {
console.error('Error saving file:', err);
} else {
console.log(`${textFileName} created successfully.`);
}
});
})
.catch((error) => {
console.error('Error occurred:', error);
});