Coder Social home page Coder Social logo

nodejs-license-file's Introduction

nodejs-license-file Circle CI

A lightweight License file generator and parser for NodeJS.

Requirements

The module requires openssl.

Basic usage

Getting started

Install nodejs-license-file with:

npm install nodejs-license-file --save

Generating license file

const licenseFile = require('nodejs-license-file');

licenseFile.generate({
   privateKeyPath: 'path/to/key.pem',
   data: 'data string'
}, (err, fileData) => {
    console.log(fileData);
});

This will produce a license key, which uses the default template and will look similar to this:

====BEGIN LICENSE====
data string
xxxxxxxxxxxxxxxxxxxxx
=====END LICENSE=====

Parse and verify license file

const licenseFile = require('nodejs-license-file');

licenseFile.parse({
    publicKeyPath: 'path/to/key.pub',
    fileData: fs.readFileSync('path/to/file.lic', 'utf8')
}, (err, data) => {
    console.log(data);
});

There is an execution result:

{
   valid: true,
   data: 'data string'
}

Advanced usage with custom template

Generating license file

const licenseFile = require('nodejs-license-file');

let template = [
    '====BEGIN LICENSE====',
    '{{&licenseVersion}}',
    '{{&applicationVersion}}',
    '{{&firstName}}',
    '{{&lastName}}',
    '{{&email}}',
    '{{&expirationDate}}',
    '{{&serial}}',
    '=====END LICENSE====='
].join('\n');

licenseFile.generate({
    privateKeyPath: 'path/to/key.pem',
    template: template,
    data: {
        licenseVersion: '1',
        applicationVersion: '1.0.0',
        firstName: 'Name',
        lastName: 'Last Name',
        email: '[email protected]',
        expirationDate: '12/10/2025'
    }
}, (err, fileData) => {
    console.log(fileData);
});

This will produce a license key, which uses the default template and will look similar to this:

====BEGIN LICENSE====
1
1.0.0
Name
Last Name
[email protected]
12/10/2025
xxxxxxxxxxxxxxxxxxxxx
=====END LICENSE=====

Parse and verify license file

const licenseFile = require('nodejs-license-file');

licenseFile.parse({
    publicKeyPath: 'path/to/key.pub',
    fileData: fs.readFileSync('path/to/file.lic', 'utf8'),
    fileParseFnc: (fileData, callback) => {
        let dataLines = fileData.split('\n');
    
        if (dataLines.length != 9) {
            return callback(new Error('LicenseFile::fileParseFnc: License file must have 9 lines, actual: ' + dataLines.length));
        }
    
        let licenseVersion     = dataLines[1];
        let applicationVersion = dataLines[2];
        let firstName          = dataLines[3];
        let lastName           = dataLines[4];
        let email              = dataLines[5];
        let expirationDate     = dataLines[6];
        let serial             = dataLines[7];
    
        callback(null, {
            serial: serial,
            data: {
                licenseVersion: licenseVersion,
                applicationVersion: applicationVersion,
                firstName: firstName,
                lastName: lastName,
                email: email,
                expirationDate: expirationDate
            }
        });
    }
}, (err, data) => {
    console.log(data);
});

There is an execution result:

{
    valid: true,
    data: {
        licenseVersion: '1',
        applicationVersion: '1.0.0',
        firstName: 'Name',
        lastName: 'Last Name',
        email: '[email protected]',
        expirationDate: '12/10/2025'
    }
}

nodejs-license-file's People

Contributors

bushev avatar r3nya avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.