Roles & permissions for Node.js, in 2 minutes.

Simple, type-safe access control for your backend. Works with MySQL, Postgres and MongoDB.

v0.1.2
$npm install permly
Live Permission Simulator
Express Guard:requirePermission(perms, "posts.publish")
Access DecisionMemory Adapter
200 OK — Access Granted

Role "editor" possesses permission "posts.publish". Route handler executes.

// In-memory permission check:
const allowed = await perms.user(userId).can("posts.publish");
Result:true (authorized)
Works identically across MySQL, Postgres & MongoDB
Developer Experience

One line to protect a route

Familiar syntax, asynchronous by design, and strict TypeScript types so typos are caught before you deploy.

permly-example
1import express from "express";
2import { requirePermission } from "permly/express";
3import { perms, setupPermissions } from "./permly.js";
4
5// Initialize tables/collections & permissions
6await setupPermissions();
7
8const app = express();
9
10// Protect route with declarative permission check
11app.post(
12 "/api/posts",
13 requirePermission(perms, "posts.create"),
14 async (req, res) => {
15 // Only users with "posts.create" (or role having it) reach here
16 const post = await createPost(req.body);
17 return res.status(201).json({ ok: true, post });
18 }
19);
Full Autocomplete
Typed role & permission strings
Sub-millisecond Checks
Built-in 60-second LRU memory cache
Zero Runtime Bloat
No heavy external frameworks
Core Capabilities

Everything you need for access control

Simple English, benefit-focused access control designed for modern Node.js backends.

Zero bloat

Zero dependencies

Nothing extra in your node_modules.

TypeScript

Type-safe

Autocomplete for your own role and permission names.

Multi-DB

Your database

MySQL, MariaDB, Postgres or MongoDB.

Middleware

Express ready

Protect routes with one line.

CLI

One-command setup

npx permly init creates everything.

In-memory

Fast

Built-in cache, cleared automatically on changes.

Built-in

Ownership rules

"Users can edit only their own posts" built in.

Concurrency

Safe under load

Tested against concurrent requests.

Verified & Tested

Built to be trusted in production

Real metrics from the codebase. Every pull request and release is validated across real database instances in automated CI pipelines.

Full
Test Matrix
4 DBs & 3 operating systems
Zero
Runtime Dependencies
No supply chain risk
~22 KB
Core Bundle Size
Fast cold starts
4
Database Adapters
PG, MySQL, MariaDB, Mongo
3
Operating Systems
Linux, macOS, Windows
MIT
Permissive License
Commercial friendly
Validated Runtime Matrix
Node.js 18+
PostgreSQL 13–17
MySQL 8.4 LTS
MariaDB 11
MongoDB 7–8
macOS / Linux / Windows

Stop writing permission checks by hand.

Move away from hardcoded role comparisons and duplicate if-statements scattered across your routes.

Before: Hand-written checks
1// Hand-written checks scattered across routes
2app.post("/api/posts/:id/publish", async (req, res) => {
3 const user = req.user;
4 const post = await getPost(req.params.id);
5
6 // Fragile if-statements, hardcoded roles
7 if (!user) return res.status(401).send();
8 if (
9 user.role !== "admin" &&
10 (user.role !== "editor" || post.authorId !== user.id)
11 ) {
12 return res.status(403).json({ error: "Forbidden" });
13 }
14
15 await publishPost(post);
16 res.json({ ok: true });
17});
After: With permly
1// Clean, declarative route guard
2app.post(
3 "/api/posts/:id/publish",
4 requirePermission(perms, "posts.publish"),
5 async (req, res) => {
6 await publishPost(req.params.id);
7 res.json({ ok: true });
8 }
9);
10
11// Or check abilities anywhere in your app
12await perms.user(userId).assignRole("editor");
13const allowed = await perms.user(userId).can("posts.publish");

Less code. One place for all access rules.

Granular Access

From whole modules down to a single button.

Give access to an entire module, one tab, or one action. Show each user only what they're allowed to see, and protect your API with the same rules.

Select Active RoleClick role to test wildcard scope

Manager: Wildcard orders.* unlocks the entire Orders module, all its tabs, and every action button.

Orders Module
Visible
Order List taborders.list.*
Access Granted
View details
Allowed
Export CSV
Allowed
Refunds taborders.refunds.*
Access Granted
View refunds
Allowed
Approve refund button
Allowed
Products Module
Visible
Catalog tabproducts.catalog.*
Access Granted
Edit pricing
Allowed
Inventory tabproducts.inventory.*
Access Granted
Adjust stock
Allowed
Reports Module
Hidden
Revenue tabreports.revenue.*
Restricted
View metrics
Denied
Audit Log tabreports.audit.*
Restricted
View audit trail
Denied
permissions.js
// Give whole module access with wildcard
await perms.role("manager").givePermission("orders.*");

// Give access to module and specific sub-tabs
await perms.role("support").givePermission("orders.access", "orders.list.*");

// Grant individual user access to one extra tab
await perms.user(42).givePermission("orders.refunds.view");

Hierarchical, intuitive wildcards

Permly evaluates wildcards from broad to specific. Assigning orders.* automatically satisfies route guards like orders.refunds.approve. No messy permission arrays or manual sync required.

Database Agnostic

Works with your existing database

No lock-in. Permly works seamlessly with SQL and NoSQL engines alike, managing its own tables or collections cleanly.

Official Adapter

PostgreSQL

Tested: 13, 14, 15, 16, 17

Uses JSONB & connection pooling with pg / postgres.js drivers.

Zero schema clutter
Official Adapter

MySQL

Tested: 8.0, 8.4 LTS

Supports mysql2 with prepared statements and row-level locking.

Zero schema clutter
Official Adapter

MongoDB

Tested: 7.0, 8.0

Native documents, subdocuments, and index-optimized permission checks.

Zero schema clutter
Official Adapter

MariaDB

Tested: 10.11, 11+

High concurrency and transaction-isolated role syncing.

Zero schema clutter
Quick Setup

Get up and running in 3 steps

From zero to a fully protected Express, Fastify, or standalone Node.js service in under two minutes.

1

Install the package

Zero external runtime dependencies. Installs in seconds.

$npm install permly
2

Initialize and run migrations

Generates configuration and creates permission tables in your selected database.

$npx permly init
$npx permly migrate
3

Assign roles and protect routes

Guard endpoints with declarative middleware or check user abilities directly.

// Assign role to a user
await perms.user(userId).assignRole("editor");
// Check permission
const canEdit = await perms.user(userId).can("posts.edit");// true
100% Free & Open Source

Support permly development

permly is free and MIT licensed. If it saves you development hours or simplifies your auth stack, please consider sponsoring or starring the project on GitHub.

Contributions, issues, and feature suggestions are always welcome.