Prerequisites
Before starting the integration, ensure you have:- Node.js version 14 or higher
- An Express.js application
- A KoruAI account with valid API credentials
Installation
Using npm
Using yarn
Using pnpm
Basic Integration
1. Import the Middleware
2. Configure Environment Variables
Create a.env
file in your project root:
Never commit your API keys to version control. Always use environment
variables or secure configuration management.
3. Add KoruAI Middleware
Advanced Configuration
Real-time Blocking
Enable real-time blocking of suspicious requests:When
blockRealtime
is enabled, KoruAI will automatically respond with a 403
status and block suspicious requests before they reach your application logic.Conditional Integration
You might want to enable KoruAI only in production:Integration Patterns
With Body Parser
If you’re using body parsing middleware, ensure proper order:With CORS
When using CORS, add KoruAI after CORS middleware:With Authentication
KoruAI works with any authentication middleware:Error Handling
KoruAI handles errors gracefully and won’t break your application:If KoruAI encounters an error, it will log the error but continue processing
the request to ensure your application remains functional.
Testing Your Integration
1. Verify Connection
After integrating KoruAI, make some test requests to your API:2. Check Dashboard
Visit your KoruAI Dashboard to verify that requests are being recorded.3. Monitor Logs
KoruAI provides helpful logs during development:Performance Considerations
Zero Latency Impact
KoruAI is designed for zero latency impact:- Asynchronous processing: Request data is sent to KoruAI servers after the response is sent to the client
- No blocking operations: Your API responses are never delayed
- Minimal memory footprint: Lightweight middleware with minimal dependencies
High Traffic Applications
For applications with high request volumes:Security Best Practices
API Key Management
✅ Do
- Store API keys in environment variables - Use different keys for different environments - Rotate keys regularly - Monitor key usage in the dashboard
❌ Don't
- Hardcode API keys in source code - Share keys between team members - Commit keys to version control - Use production keys in development
Environment Configuration
Troubleshooting
Common Issues
Requests not showing in dashboard
Requests not showing in dashboard
Possible causes:
- Incorrect API key or App ID
- Network connectivity issues
- Middleware not properly configured
- Verify your credentials in the dashboard
- Check network connectivity
- Ensure middleware is added before your routes
Application performance issues
Application performance issues
Possible causes:
- Synchronous operations (should not happen with KoruAI)
- Network latency to KoruAI servers
- KoruAI operates asynchronously - contact support if you experience latency
- Check your network configuration
Real-time blocking not working
Real-time blocking not working
Possible causes:
blockRealtime
not enabled- No policies created yet
- Insufficient training data
- Set
blockRealtime: true
in configuration - Create policies in the dashboard after collecting sufficient traffic
- Ensure you have at least 100 requests per endpoint
Debug Mode
Enable debug logging for troubleshooting:Next Steps
Once you have KoruAI integrated:- Generate Traffic: Use your API normally to collect training data
- Create Policies: Use the dashboard to generate AI-powered security rules
- Monitor Analytics: Review security insights and blocked threats
- Fine-tune Settings: Adjust configuration based on your needs