NPM module to generate a QR Code for WIFI ssid and password
npm install wifi-qr-code-generatorāļø Star us on GitHub ā it helps!
wifi-qr-code-generator is an npm module to generate a QR Code to connect to your WiFi. Supports WiFi QR Codes in PNG, SVG, Terminal and UTF output formats. Works in both node server and browser.
Using NPM:
``sh`
$ npm install wifi-qr-code-generator
Using Yarn:
`sh`
$ yarn add wifi-qr-code-generator
`javascript`
const qrcode = require('wifi-qr-code-generator')
const pr = qrcode.generateWifiQRCode({
ssid: 'Hello world',
password: 'testpass',
encryption: 'WPA',
hiddenSSID: false,
outputFormat: { type: 'image/png' }
})
pr.then((data) => console.log(data))
This prints the following output:
``
data:image/png;base64,iVBORw0KGgoAAA...
You can pass this data URL to an html img tag to generate the following QR code image:

Main API call is generateWifiQRCode which is shown in the example above. This method takes an object of the following format:
`typescript
export interface Config {
ssid: string
password: string
encryption: 'WPA' | 'WEP' | 'None'
hiddenSSID: boolean
outputFormat: OutputFormat
}
export interface OutputFormat {
type: 'image/png' | 'utf8' | 'svg' | 'terminal'
}
`
1. ssid: string representation of your wireless SSID (Wifi name). Max length possible for WiFi SSID is 32 characters for most routers. However this library doesn't impose any limitation on the length of SSID that can be passed in.password
1. : string representation of your WiFi passwordencryption
1. : Possible values here are WPA, WEP and None. If you are using WPA2, enter WPA. Please note that WEP protocol has multiple security vulnerabilities and you shouldn't be configuring your WiFi router to use WEP at all.hiddenSSID
1. : should be true if your router is configured to NOT broadcast your SSID. Else falseoutputFormat
1. : An object that has a single type field
Possible values of type are:
1. "image/png": generateWifiQRCode will generates a data URL representing a PNG image"svg"
1. : generateWifiQRCode will generates an SVG image in string formatutf8
1. : generateWifiQRCode will generates a UTF8 representation of the QR codeterminal
1. : generateWifiQRCode will generates a string that can be pretty printed as QR code in the terminal
`javascript`
const qrcode = require('wifi-qr-code-generator')
const pr = qrcode.generateWifiQRCode({
ssid: 'Hello world',
password: 'testpass',
encryption: 'WPA',
hiddenSSID: false,
outputFormat: { type: 'svg' }
})
pr.then((data) => console.log(data))
This prints the following output:
``
You can use the generated SVG directly in your HTML page to display the QR code.
`javascript`
const qrcode = require('wifi-qr-code-generator')
const pr = qrcode.generateWifiQRCode({
ssid: 'Hello world',
password: 'testpass',
encryption: 'WPA',
hiddenSSID: false,
outputFormat: { type: 'utf8' }
})
pr.then((data) => console.log(data))
This prints the following output:
`
āāāāāāā āāā ā āāāā āāāāāā āāāāāāā
ā āāā ā āāāāā ā āāā āāā ā āāā ā
ā āāā ā āā ā āā āā āā āā ā āāā ā
āāāāāāā āāāāāāā āāāāāāā ā āāāāāāā
ā āāāāāāāā āā āāāāāā āāāā āāāāā
āāāāā āāā āāā ā āāā āā āāā āā ā
ā āāāāāāā āāāāā āāāāāāāāāāā āāāāā
āāāāāāāāāāāāā āāāāā āāā ā ā āā
ā āāāāā āā ā āāāā āā ā āāāā āā āā
āāāāāāā āāāā āā āāāāā ā ā āāā āā
ā ā ā āāāāā āā āāā āāā āāāā ā āā
ā āāāāā āāāāāāāāāāā āāāāāā āāāā
āā ā āāāāāāāā āāā āāāāāāāāā ā
āāāāāāā āāā āā ā ā āāāāā ā ā āāā
ā āāā ā āāāāā āā āāāāā āāāāāāāāā
ā āāā ā āā āāāāāā ā ā āā āā āā
āāāāāāā ā āā āā āāā āā āāā
`
`javascript``
const qrcode = require('wifi-qr-code-generator')
const pr = qrcode.generateWifiQRCode({
ssid: 'Hello world',
password: 'testpass',
encryption: 'WPA',
hiddenSSID: false,
outputFormat: { type: 'terminal' }
})
pr.then((data) => console.log(data))
This generates the following QR code in your terminal:

š¤ Anoop Kunjuraman
- Website: https://anoop.kunjuraman.com
- Twitter: @anoopengineer
- Github: @anoopengineer
- LinkedIn: @anoopkunjuraman
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a āļø if this project helped you!
Copyright Ā© 2020 Anoop Kunjuraman.
This project is MIT licensed.
---
_This README was generated with ā¤ļø by readme-md-generator_