#QR RCODE GENERATOR CODE#
Heck yeah! No more need to ship that entire package with the rest of the scripts! We can hit that URL and generate the QR code from there. What’s the URL? There’s a command for that: doctl sbx fn get sample/qr -url Once deployed, we can access the function at a URL. Now we can deploy the function: doctl sandbox deploy qr-generator We can do it straight from the command line! First, we connect to the DigitalOcean sandbox environment so we have a live URL for testing: # You will need an DO API key handy It’s hello by default when we spin up the project, but we named ours qr.js, so we oughta change that line from hello to qr before moving on. The actions/ name property is the name of the function itself, which is the name of the file.
![qr rcode generator qr rcode generator](https://ph-files.imgix.net/1e891e5f-41ac-4f3c-a2fe-c026bab5cde1.png)
See those highlighted lines? The packages: name property is where in the packages folder the function lives, which is a folder called sample in this case. This is what’s in there by default: targetNamespace: '' When the project was scaffolded, we got this little project.yml file and it configures the function with some information about it.
![qr rcode generator qr rcode generator](https://media.cdnandroid.com/item_images/197454/imagen-qr-code-generator-0big.jpg)
We can even test it out in the terminal: doctl serverless functions invoke sample/qr -p "text:" Check the config file Return qrcode.toDataURL(args.text).then(res => ().then(console.log)Īll that’s doing is requiring the the qrcode package and exporting a function that basically generates an tag with the a base64 PNG for the source. Now we can write the function in a new qr.js file: const qrcode = require('qrcode')
#QR RCODE GENERATOR INSTALL#
So, let’s cd into packages/sample/qr and install the package: npm install -save qrcode That folder is where both the qrcode package and our qr.js function are going to live. There’s a sample function in there, but we can overlook it for now and create a qr folder right next to it: We get a nice clean project called qr-generator with a /packages folder that holds all the project’s functions. DigitalOcean functions also support PHP and Python. Notice the language is explicitly declared. Create a functions folder locallyĭigitalOcean has a CLI that with a command that’ll scaffold things for us, so cd wherever you want to set things up and run: doctl serverless init -language js qr-generator
#QR RCODE GENERATOR GENERATOR#
In return, we ask you to implement a back-link with the text 'TEC-IT Barcode Generator ' on your web-site. DigitalOcean happens to be one of them! And, like Droplets, functions are pretty easy to deploy. This Barcode Generator is Free You may use this barcode generator as part of your non-commercial web-application or web-site to create barcodes, QR codes and other 2D codes with your own data. Some hosts offer some sort of cloud function feature. Sorta like a little API to run the function. That way, the function lives somewhere on a server that can be called when it’s needed. Now, I’m relatively new to the concept of cloud functions, but I hear that’s the bee’s knees for something just like this. You wouldn’t want to serve all that along with the rest of your scripts. But it’s also weighs in at a hefty 180 KB for everything it needs to generate stuff. There are like a gazillion QR code generators out there, but say it’s something you need to do on your own website.
![qr rcode generator qr rcode generator](https://www.techicy.com/wp-content/uploads/2019/08/QR-Code-Generator-Online-990x671.png)
Anyways, they’ve lately been popping up again and it got me thinking about how they’re made. QR codes are funny, right? We love them, then hate them, then love them again.