-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (26 loc) · 842 Bytes
/
index.js
File metadata and controls
37 lines (26 loc) · 842 Bytes
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
37
import inquirer from 'inquirer';
import qr from 'qr-image';
import fs from 'fs';
const askForURL = async () => {
const response = await inquirer.prompt([
{
type: 'input',
name: 'url',
message: 'Enter a URL:',
validate: function (input) {
const urlRegex = /^(http|https):\/\/[^ "]+$/;
return urlRegex.test(input) || 'Please enter a valid URL';
},
},
]);
const enteredURL = response.url;
const filePath = 'entered_url.txt';
fs.writeFileSync(filePath, enteredURL);
console.log(`URL saved to: ${filePath}`);
const qrCode = qr.image(enteredURL, { type: 'png' });
const qrCodePath = 'qrcode.png';
// Saving the QR code image to a file
qrCode.pipe(fs.createWriteStream(qrCodePath));
console.log(`QR code generated and saved to: ${qrCodePath}`);
};
askForURL();