What it does
permly adds roles and permissions to your Node.js app. Users get roles like editor, roles get permissions like posts.create, and you check them with one line.
It's for developers who want access control that works in minutes: run one command, and permly sets up the tables and a ready-to-use file for your database.
When to use it
Use permly if your app has:
- Users with different access levels (admin, editor, viewer...)
- Rules like "editors can edit any post" or "authors can edit only their own posts" (using ownership checks)
- Roles that admins can create or change at runtime
- MySQL, MariaDB, Postgres or MongoDB, with Express or any Node.js code
permly works with your existing login system. It doesn't handle login or sessions, only "who can do what".
When permly may not be the right fit
- Rules that depend on data conditions, like "allowed only if the post is a draft" or "only during working hours". permly checks roles, permissions and ownership; you can still combine a permly check with your own
ifin code. - Field-level rules, like "show the salary field only to HR". You can handle simple cases with a separate permission (e.g.
"users.view_salary"). - Policies written by end users in a rule language.
How it works
- List your permissions in config:
["posts.create", "posts.edit", "posts.delete"] - List your roles:
["admin", "editor", "viewer"] - Grant permissions to roles: admin gets
*(everything), editor getsposts.create,posts.edit, etc. - Assign roles to users:
perms.user(1).assignRole("editor") - Check before action:
if (await perms.user(1).can("posts.create")) { ... }
Permissions live in your database, so changes survive restarts. Checks are cached (60 seconds by default) so they're fast.
The benefits
- Type-safe in TypeScript — typos like
"posts.edt"are compile errors - Works in seconds —
npx permly init && npx permly migrate - One model, not scattered if-statements — permissions are in one place
- Handles edge cases — wildcards (
posts.*), ownership (canOwn), concurrency - Zero runtime dependencies — small core, fast starts
- Works with plain JavaScript too — not TypeScript-only
Next steps
- Try it now: Quick Start
- Learn the core: Core Concepts
- Set it up: Installation