# nodejs-license-file

> A lightweight License file generator and parser for NodeJS.

Latest version **4.0.0** (published 2018-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install nodejs-license-file
pnpm add nodejs-license-file
yarn add nodejs-license-file
bun add nodejs-license-file
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2018-03-03 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/nodejs-license-file) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 74 |
| Author | Yuriy Bushev |
| Maintainers | bushev |
| Keywords | license, file, generation, parsing, validation |

## Links

- npm: https://www.npmjs.com/package/nodejs-license-file
- Repository: https://github.com/bushev/nodejs-license-file
- Issues: https://github.com/bushev/nodejs-license-file/issues
- npm.io page: https://npm.io/package/nodejs-license-file

## Dependencies (1)

- [json-stable-stringify](https://npm.io/package/json-stable-stringify.md) 1.0.1

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2018-03-03
- 3.0.0 — 2017-12-18
- 2.0.1 — 2017-11-26
- 2.0.0 — 2017-11-26
- 1.1.4 — 2017-11-26
- 1.1.3 — 2017-11-22
- 1.1.2 — 2017-11-21
- 1.1.1 — 2017-11-21
- 1.1.0 — 2017-04-04
- 1.0.2 — 2016-03-02
- 1.0.1 — 2016-02-29
- 1.0.0 — 2016-02-29

## README

## nodejs-license-file [![Build Status](https://travis-ci.org/bushev/nodejs-license-file.svg?branch=master)](https://travis-ci.org/bushev/nodejs-license-file)

A lightweight License file generator and parser for NodeJS.

## Generate a keypair using OpenSSL

1. Generate an RSA 2048 bit private key

    `openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048`

2. Extract the public key from an RSA keypair

    `openssl rsa -pubout -in private_key.pem -out public_key.pem`

## Generating license file

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

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

try {
 
    const licenseFileContent = licenseFile.generate({
        privateKeyPath: 'path/to/key.pem',
        template,
        data: {
            licenseVersion: '1',
            applicationVersion: '1.0.0',
            firstName: 'Name',
            lastName: 'Last Name',
            email: 'some@email.com',
            expirationDate: '12/10/2025'
        }
    });
    
    console.log(licenseFileContent);

} catch (err) {
    
    console.log(err);
}
```

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
some@email.com
12/10/2025
xxxxxxxxxxxxxxxxxxxxx
=====END LICENSE=====
```

## Parse and verify license file

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

try {
 
    const data = licenseFile.parse({
        publicKeyPath: 'path/to/key.pub',
        licenseFilePath: 'path/to/file.lic',
        template
    });
    
    console.log(data);
    
} catch (err) {
    
    console.log(err);
}
```

There is an execution result:
```
{
    valid: true,
    serial: 'oZDqoEr2avwhAqwV4HInq9otNzeBeD/azq2yn2jA ...',
    data: {
        licenseVersion: '1',
        applicationVersion: '1.0.0',
        firstName: 'Name',
        lastName: 'Last Name',
        email: 'some@email.com',
        expirationDate: '12/10/2025'
    }
}
```

NOTICE: All numeric data will be converted to strings after parsing. You need to take care of a parsed data types.

---
_Source: https://npm.io/package/nodejs-license-file · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
