-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (30 loc) · 802 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
import inquirer from 'inquirer';
import qr from 'qr-image';
import fs from 'fs';
inquirer
.prompt(
[
{
message:' Type in your URL please : ',
name:'URL',
type:'input',
},
]
)
.then((ans)=>{
const url = ans.URL ;
const randomStr = Math.floor(Math.random() * 1000000).toString(36) ;
const qr_png = qr.image(url);
qr_png.pipe(fs.createWriteStream(`./images/qr_code_${randomStr}.png`));
fs.appendFile('url.txt',`\n${randomStr} -> ${url}`,(err)=>{
if(err) throw err;
console.log('file has been created')
})
})
.catch((error)=>{
if(error.isTtyError){
console.error(" Prompt couldn't be rendered in the current environment ");
}else{
console.error(" Something else went wrong ");
}
})