Back to Templates

Protect your NestJS API with Unkey

Starter kit for NestJS protected by Unkey

Written by
djnovin
Framework
NestJS
Language
Typescript
Starter kit for NestJS protected by Unkey

Unkey Node.js Example

This is an example of how to use the Unkey API with NestJS.

Table of Contents

Table of Contents

Quickstart

Create a root key

  1. Go to /settings/root-keys and click on the "Create New Root Key" button.
  2. Enter a name for the key.
  3. Select the following workspace permissions: create_key, read_key, encrypt_key and decrypt_key.
  4. Click "Create".

Create your API

  1. Go to https://app.unkey.com/apis and click on the "Create New API" button.
  2. Give it a name.
  3. Click "Create".

Create your first API key

  1. Click "Create Key" in the top right corner.
  2. Feel the form with any key information you want or leave it empty.
  3. Click "Create"
  4. Copy the key and save it somewhere safe.

Set up the example

  1. Clone the repository to your local machine.
1
2git clone <repo-url>
3cd /path/to/repo
4
  1. Duplicate the .env.example file and rename it to .env.
1
2cp .env.example .env
3
  1. Replace your API key in the .env file.

  2. Install the dependencies.

1
2pnpm install
3
  1. Run the application.
1
2pnpm run start
3
  1. Test the public route as a guest:
1
2curl http://localhost:3000/api/v1/public
3
  1. Test the protected route, which requires valid authorization:
1
2curl http://localhost:3000/api/v1/protected -H "Authorization: Bearer <YOUR_API_KEY>"
3

License

This project is licensed under the MIT License - see the LICENSE file for details.

Protect your API.
Start today.

2500 verifications and 100K successful rate‑limited requests per month. No CC required.