Written by Sümeyye Sever (notes I took while creating web development projects)
A simple Node.js project
/*
1- Use the inquirer npm package to get user input
2- Use the qr-image npm package to turn the user entered URL into a QR code image.
3- Create a txt file to save the user input using the native fs node module.
*/
import { input } from '@inquirer/prompts';
import qr from "qr-image"
import fs from "fs"
// 1 - first install inquirer package -> npm i @inquirer/prompts
const userURL = await input({ message: 'Enter the URL that you want to turn it to a QR Code:' });
// 2 -> npm i qr-image
var qr_svg = qr.image(userURL, { type: 'png' });
qr_svg.pipe(fs.createWriteStream('userURL.png'));
// 3
fs.writeFile('userURL.txt', userURL, function (err) {
if (err) throw err;
console.log('Saved!');
});
Save the code and run the node index.js command on terminal.
✔ Enter the URL that you want to turn it to a QR Code: <https://sumeyyesever.netlify.app/>
Saved!
