🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

najm-middleware

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

najm-middleware

middleware .

latest
npmnpm
Version
0.0.6
Version published
Maintainers
1
Created
Source

najm-middleware

Middleware plugin for the Najm framework with decorator support.

Features

  • Context storage middleware (Hono's async local storage)
  • Request context middleware with ALS (Async Local Storage) integration
  • User functional middleware support
  • DI support in middleware classes
  • Order-based execution system
  • Path-based middleware application
  • Decorator support with @Middleware() and @Use()

Installation

npm install najm-middleware

Usage

Basic (Auto-loaded)

// Server auto-loads middleware plugin
new Server()
  .load(MyController)
  .listen(3000);

With Functional Middleware

new Server()
  .middleware(cors(), compress(), helmet())
  .load(MyController)
  .listen(3000);

With @Middleware() Class

@Middleware({ order: 20, path: '/api/*' })
class AuthMiddleware {
  constructor(private auth: AuthService) {}

  async use(ctx: Context, next: Next) {
    const token = ctx.req.header('authorization');
    if (!token) throw new HttpError(401, 'Unauthorized');

    const user = await this.auth.verify(token);
    ctx.set('user', user);

    await next();
  }
}

new Server()
  .middleware(cors())
  .load(MyController, AuthMiddleware)
  .listen(3000);

With @Use() Decorator

@Service()
class MiddlewareConfig {
  @Use({ order: 10 })
  cors = cors({ origin: '*' });

  @Use({ order: 15 })
  compress = compress();

  @Use({ order: 20, path: '/api/*' })
  rateLimit = rateLimiter({ max: 100 });
}

new Server()
  .load(MyController, MiddlewareConfig)
  .listen(3000);

With Plugin Config

new Server()
  .use(middleware({
    debug: true,
    requestIdHeader: 'x-trace-id',
    exclude: ['/health', '/metrics'],
    use: [cors(), helmet()],
  }))
  .load(MyController)
  .listen(3000);

Execution Order

OrderSourceExample
1Corecontext-storage
2Corerequest-context (ALS)
10-49ReservedFuture core middleware
50+.middleware()cors, compress, helmet
60+.use(middleware({ use: [...] }))Config middleware
100+@Middleware()AuthMiddleware
100+@Use()Property middleware

License

MIT

FAQs

Package last updated on 19 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts