└── 2.4+QR+Code+Project └── 2.4 QR Code Project ├── URL.txt ├── package.json ├── qr_img.png └── solution.js /2.4+QR+Code+Project/2.4 QR Code Project/URL.txt: -------------------------------------------------------------------------------- 1 | https://youtube.com -------------------------------------------------------------------------------- /2.4+QR+Code+Project/2.4 QR Code Project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "fs": "^0.0.1-security", 4 | "inquirer": "^9.2.16", 5 | "qr-image": "^3.2.0" 6 | }, 7 | "name": "2.4-qr-code-project", 8 | "version": "1.0.0", 9 | "type": "module", 10 | "main": "index.js", 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "", 16 | "license": "ISC", 17 | "description": "" 18 | } 19 | -------------------------------------------------------------------------------- /2.4+QR+Code+Project/2.4 QR Code Project/qr_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Axshaya/QR-code-generator/38625555555aff2ca2d2a54ba9473bd79ed95825/2.4+QR+Code+Project/2.4 QR Code Project/qr_img.png -------------------------------------------------------------------------------- /2.4+QR+Code+Project/2.4 QR Code Project/solution.js: -------------------------------------------------------------------------------- 1 | import inquirer from "inquirer"; 2 | import qr from "qr-image"; 3 | import fs from "fs"; 4 | 5 | inquirer 6 | .prompt([ 7 | { 8 | message: "Type in your URL: ", 9 | name: "URL", 10 | }, 11 | ]) 12 | .then((answers) => { 13 | const url = answers.URL; 14 | var qr_svg = qr.image(url); 15 | qr_svg.pipe(fs.createWriteStream("qr_img.png")); 16 | 17 | fs.writeFile("URL.txt", url, (err) => { 18 | if (err) throw err; 19 | console.log("The file has been saved!"); 20 | }); 21 | }) 22 | .catch((error) => { 23 | if (error.isTtyError) { 24 | // Prompt couldn't be rendered in the current environment 25 | } else { 26 | // Something else went wrong 27 | } 28 | }); 29 | /* 30 | 1. Use the inquirer npm package to get user input. 31 | 2. Use the qr-image npm package to turn the user entered URL into a QR code image. 32 | 3. Create a txt file to save the user input using the native fs node module. 33 | */ 34 | --------------------------------------------------------------------------------