A fast, lightweight, and zero-dependency Node.js web framework built for performance and simplicity.
- Zero Dependencies - No external dependencies, pure Node.js
- High Performance - Built for speed with optimized request handling
- Middleware Support - Express-like middleware system
- Advanced Router - Powerful routing with parameter support
- Session Management - Built-in session handling with auto-save
- Security First - CORS, CSRF, rate limiting, and security headers
- TypeScript Support - Full TypeScript definitions included
- Memory Efficient - Optimized for low memory usage
- Easy to Use - Simple, intuitive API
npm install @oxog/spark
const { Spark } = require('@oxog/spark');
const app = new Spark();
app.get('/', (ctx) => {
ctx.json({ message: 'Hello World!' });
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
- π Complete Documentation - Full documentation index
- π Getting Started - Quick start guide
- π API Reference - Complete API documentation
- π§ Middleware Guide - Comprehensive middleware guide
- π’ Beginner Level - Start here if you're new to Spark
- π‘ Intermediate Level - Build sophisticated applications
- π΄ Expert Level - Master advanced patterns and architecture
- Security Best Practices - Security guidelines
- Deployment Guide - Production deployment instructions
The main Spark application class that handles server lifecycle, middleware, and routing.
Advanced routing system with support for parameters, middleware, and nested routes.
Request/response context object with helper methods for common operations.
Extensible middleware system with built-in middleware for common tasks.
- Body Parser - Parse JSON, form data, and text
- CORS - Cross-origin resource sharing
- Session - Session management with auto-save functionality
- Security - Security headers and protection
- Rate Limiting - Request rate limiting
- Compression - Response compression
- Static Files - Static file serving
- Logger - Request logging
- Health Check - Health monitoring endpoints
Spark is designed for high performance with minimal overhead:
- ~4000 req/sec on standard hardware
- <1ms average response time
- <50MB memory footprint
- Zero external dependencies
βββββββββββββββββββ
β Application β
βββββββββββββββββββ€
β Middleware β
βββββββββββββββββββ€
β Router β
βββββββββββββββββββ€
β Context β
βββββββββββββββββββ€
β HTTP Server β
βββββββββββββββββββ
Spark includes built-in security features:
- CORS protection
- CSRF protection
- Rate limiting
- Security headers
- Input validation
- XSS protection
# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:examples
# Run performance benchmarks
npm run benchmark
const { Spark } = require('@oxog/spark');
const app = new Spark();
app.get('/users', (ctx) => {
ctx.json([
{ id: 1, name: 'John Doe' },
{ id: 2, name: 'Jane Smith' }
]);
});
app.get('/users/:id', (ctx) => {
const { id } = ctx.params;
ctx.json({ id, name: 'User ' + id });
});
app.listen(3000);
const { Spark } = require('@oxog/spark');
const app = new Spark();
// Global middleware
app.use(require('@oxog/spark/middleware/logger')());
app.use(require('@oxog/spark/middleware/cors')());
// Route-specific middleware
app.get('/protected',
require('@oxog/spark/middleware/auth'),
(ctx) => {
ctx.json({ message: 'Protected route' });
}
);
app.listen(3000);
const { Spark, Router } = require('@oxog/spark');
const app = new Spark();
const api = new Router();
// Session middleware with auto-save
app.use(require('@oxog/spark/middleware/session')({
secret: 'your-secret-key',
saveUninitialized: true,
cookie: {
maxAge: 24 * 60 * 60 * 1000, // 24 hours
httpOnly: true,
secure: process.env.NODE_ENV === 'production'
}
}));
// Authentication
api.post('/auth/login', (ctx) => {
const { email, password } = ctx.body;
if (authenticate(email, password)) {
ctx.session.userId = user.id; // Auto-saved immediately
ctx.json({ success: true });
} else {
ctx.status(401).json({ error: 'Invalid credentials' });
}
});
// Protected routes
api.get('/orders', requireAuth, (ctx) => {
const orders = getOrdersByUser(ctx.session.userId);
ctx.json({ orders });
});
app.use('/api', api.routes());
app.listen(3000);
Contributions are welcome! Please read our Contributing Guide for details.
MIT License - see the LICENSE file for details.
If you find Spark useful, please consider giving it a star on GitHub!
Built with β€οΈ by the Spark team