DEV Community

MC Naveen
MC Naveen

Posted on

How to Generate License Key with Node.js

This post will help you to generate License keys with Node.js

I'll walk you through step by step process

Create a directory

mkdir license-key
Enter fullscreen mode Exit fullscreen mode

cd into the Directory

cd license-key
Enter fullscreen mode Exit fullscreen mode

Initiate Yarn

yarn init -y
Enter fullscreen mode Exit fullscreen mode

Install the required dependency

yarn add @mcnaveen/license-gen
Enter fullscreen mode Exit fullscreen mode

Create a new file called index.js and paste the below code.

const licenseGen = require("@mcnaveen/license-gen")

const key = licenseGen(32)
console.log(key)
Enter fullscreen mode Exit fullscreen mode

Now Save the File
Then Run node index.js
You'll get the license key in console like below

TPL5-IAQV-TUCR-8N7A-AQBW-EFSQ-HLK7-BND6
Enter fullscreen mode Exit fullscreen mode

You can alter the license key as per your need.

If you want more characters, change the value from 32 to something else.

Or if you need pair of 8 values with the same 32 characters modify the code like this.

const licenseGen = require("@mcnaveen/license-gen")

const key = licenseGen(32, 8)
console.log(key)
Enter fullscreen mode Exit fullscreen mode

Then you'll get the output like this

BONP7PMW-2T4CTB58-9EOJT7CU-Q72TVKGL
Enter fullscreen mode Exit fullscreen mode

This module as supports ES6 imports

If you like this post leave a heart, or Bookmark it for later.

Please comment your thoughts


Links:

Top comments (0)