Introduction
Welcome to Nexus API Framework, a modern, high-performance web framework designed for building scalable applications with ease. Nexus combines the best practices from years of web development experience with cutting-edge technology to deliver an exceptional developer experience.
Whether you're building a simple API, a complex microservices architecture, or a real-time application, Nexus provides the tools and patterns you need to succeed. With built-in support for WebSockets, automatic API documentation, and a powerful plugin system, you can focus on building features instead of infrastructure.
Why Nexus?
Nexus was built from the ground up to solve common pain points in modern web development. Here's what sets it apart:
- Performance First: Built on top of the fastest Node.js runtime with zero-overhead abstractions
- Type Safety: Full TypeScript support with intelligent type inference throughout the framework
- Developer Experience: Intuitive APIs, excellent error messages, and comprehensive documentation
- Production Ready: Battle-tested patterns, built-in monitoring, and automatic performance optimization
- Extensible: Powerful plugin system that allows you to extend functionality without modifying core code
- Modern Standards: Support for latest web standards including HTTP/3, WebSockets, and Server-Sent Events
Key Features
Intelligent Routing
Nexus's routing system is designed for both simplicity and power. Define routes with intuitive syntax, including support for path parameters, query strings, and wildcard matching:
import { createApp } from '@nexus/sdk';
const app = createApp({ port: 3000 });
// Simple route
app.route('/api/hello', (req, res) => {
res.json({ message: 'Hello, World!' });
});
// Route with parameters
app.route('/api/users/:id', (req, res) => {
const userId = req.params.id;
res.json({ userId, name: 'John Doe' });
});
// Wildcard route
app.route('/api/files/*', (req, res) => {
const filePath = req.params['*'];
res.sendFile(filePath);
});
app.start();
Middleware Pipeline
Create powerful request processing pipelines with middleware. Chain together multiple middleware functions to handle authentication, logging, validation, and more:
import { createApp, auth, logger, cors } from '@nexus/sdk';
const app = createApp();
// Global middleware
app.use(logger());
app.use(cors({ origin: '*' }));
// Route-specific middleware
app.route('/api/protected',
auth({ required: true }),
(req, res) => {
res.json({ user: req.user });
}
);
app.start();
Installation
Getting started with Nexus is simple. Install the framework using your preferred package manager:
npm install @nexus/sdk
Or with Yarn:
yarn add @nexus/sdk
Or with pnpm:
pnpm add @nexus/sdk
System Requirements
Before installing Nexus, ensure your system meets the following requirements:
- Node.js 18.0 or higher (LTS version recommended)
- npm 8.0 or higher, or equivalent package manager
- TypeScript 5.0 or higher (if using TypeScript)
- At least 1GB of available RAM
- Linux, macOS, or Windows operating system
Core API Endpoints
Nexus applications expose several core endpoints by default. Here's a reference table of the most commonly used endpoints:
| Endpoint | Method | Description | Auth Required |
|---|---|---|---|
/health |
GET | Health check endpoint for monitoring | No |
/api/docs |
GET | Auto-generated API documentation | No |
/api/v1/users |
GET | List all users with pagination | Yes |
/api/v1/users/:id |
GET | Get specific user by ID | Yes |
/api/v1/users |
POST | Create a new user | Yes |
/api/v1/users/:id |
PUT | Update existing user | Yes |
/api/v1/users/:id |
DELETE | Delete user | Yes |
/ws |
WS | WebSocket connection endpoint | Optional |
Configuration Example
Nexus uses a simple configuration object to customize your application. Here's a comprehensive example showing all available options:
import { createApp } from '@nexus/sdk';
const app = createApp({
// Server configuration
port: process.env.PORT || 3000,
host: '0.0.0.0',
// Security settings
cors: {
origin: ['https://example.com', 'https://app.example.com'],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']
},
// Rate limiting
rateLimit: {
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: 'Too many requests, please try again later'
},
// Logging configuration
logger: {
level: 'info',
format: 'json',
output: './logs/app.log'
},
// Database connection
database: {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'nexus',
password: process.env.DB_PASSWORD,
database: 'nexus_db',
ssl: true
},
// Plugin configuration
plugins: [
'@nexus/plugin-swagger',
'@nexus/plugin-metrics',
'@nexus/plugin-compression'
]
});
app.start();
Next Steps
Now that you understand the basics of Nexus API Framework, you're ready to dive deeper. Here are some recommended next steps:
- Follow the Quick Start Guide to build your first application
- Explore the Architecture documentation to understand how Nexus works under the hood
- Check out the REST API Reference for detailed endpoint documentation
- Learn about Plugins to extend Nexus's functionality
- Read the Deployment Guide to take your app to production