Registry / security / acl2
library4.3.0jsnpmunverified

Access Control List module for Node.js with Express middleware support. Version 4.3.0, actively maintained with regular releases. Forked from the original `acl` package to provide modern code infrastructure, Promises-only API, and improved backends for Redis, MongoDB, and in-memory storage. Key differentiators include breaking changes like constructor options objects instead of multiple arguments, default 'acl_' prefix, and full TypeScript type definitions.

npm install acl2
INSTALL
IMPORT
SIG · ACL2
A
acl2
securityjavascriptv4.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ACL
const ACL = require('acl2');
import ACL from 'acl2';
CommonJS only; no default ESM export. Use require.
redisBackend
const { redisBackend } = require('acl2');
const { RedisBackend } = require('acl2');
Case-sensitive name: 'redisBackend'.
mongodbBackend
const { mongodbBackend } = require('acl2');
import { mongodbBackend } from 'acl2';
Cannot use ESM import; use destructured require.
memoryBackend
const { memoryBackend } = require('acl2');
(none)
Memory backend constructor, no external dependencies required.

Basic setup with Redis backend, creating a role 'guest' with permission to view blogs, assigning role to a user, and checking permission.

const ACL = require('acl2'); const { redisBackend } = require('acl2'); const redis = require('redis'); const client = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); await client.connect(); const acl = new ACL(new redisBackend({ redis: client })); await acl.allow('guest', 'blogs', 'view'); await acl.addUserRoles('user1', 'guest'); const allowed = await acl.isAllowed('user1', 'blogs', 'view'); console.log(allowed); // true
Debug
Known issues
breakingBackend constructors now take an options object instead of multiple arguments. E.g., new ACL.redisBackend({ redis: client }) instead of new ACL.redisBackend(client).
fix
Update constructor calls: use options object with appropriate keys.
affects: >=4.0.0
breakingNew default prefix 'acl_' for both Redis and MongoDB backends. Previously no prefix or empty string.
fix
If you relied on no prefix, explicitly set { prefix: '' } in backend options.
affects: >=4.0.0
breakingPromises-only API: callbacks no longer supported. All async methods return promises.
fix
Replace callback-based code with async/await or .then().
affects: >=4.0.0
deprecatedThe original 'acl' package is unmaintained; 'acl2' is its replacement.
fix
Migrate to acl2 as documented above.
affects: n/a
gotchaCommonJS only: acl2 does not provide ESM exports. Using import will throw.
fix
Use require('acl2') instead of import statements.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: acl.allow is not a function
ACL instance not created correctly (e.g., forgot 'new' when instantiating ACL class).
fix
const acl = new ACL(new ACL.memoryBackend());
Error: Redis connection error: getaddrinfo ENOTFOUND
Invalid Redis host or Redis not running.
fix
Check REDIS_URL environment variable or ensure Redis is running locally.
MongoError: The 'db' option is required
MongoDB backend constructed without providing client or db connection object.
fix
const acl = new ACL(new ACL.mongodbBackend({ client: mongoClient }));
Cannot find module 'acl2'
Package not installed.
fix
Run: npm install acl2
Upgrade
Version history
4.3.0latest on npm
Audit
Dependencies
mongodboptionalRequired for MongoDB backend (optional, install separately)
redisoptionalRequired for Redis backend (optional, install separately)
Agent activity
55 hits · last 30 days
node
44
Perplexity
1
OpenAI (training)
1
Resources
packageacl2
acl2 — npm install acl2 · libregistry