@qnx/interfaces
v0.8.8
Published
Collection of core functions
Readme
@qnx/interfaces
@qnx/interfaces provides a collection of shared TypeScript interfaces and type augmentations for use across Node.js/Express applications, including typed request objects, user models, and common message shapes.
✨ Features
- Typed
Requestwithuserproperty for authenticated routes - Common
UserandMessageinterfaces - Re-exports Express
ResponseandNextFunctionfor convenience
📦 Installation
Install via your preferred package manager:
# npm
npm install @qnx/interfaces
# yarn
yarn add @qnx/interfaces
# pnpm
pnpm install @qnx/interfacesPeer Dependencies
This package requires express as a peer dependency:
npm install express🚀 Usage
Authenticated Request
Use the typed Request in route handlers to access req.user without casting:
import type { Request, Response, NextFunction } from '@qnx/interfaces'
export function authMiddleware(req: Request, res: Response, next: NextFunction) {
console.log(req.user.id) // typed as User
next()
}User Interface
import type { User } from '@qnx/interfaces'
const user: User = {
id: '123',
name: 'John Doe',
email: '[email protected]',
password: 'hashed_password'
}Message Interface
import type { Message } from '@qnx/interfaces'
const response: Message = {
message: 'Operation completed successfully.'
}🤝 Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change. Make sure to update or add tests where appropriate.
📄 License
MIT License © 2023-PRESENT Yatendra Kushwaha
