🚀 Modern TypeScript backend framework designed exclusively for Bun runtime.
- 🔥 Bun Native - Built specifically for Bun, no Node.js support
- ⚡ TypeScript First - 100% TypeScript, no JavaScript support
- 🛣️ Fast Routing - Efficient path matching with parameter extraction
- 🔧 Middleware System - Composable middleware chain
- 🎯 Decorators - Clean controller-based routing with decorators
- 📦 Modern APIs - Uses Web APIs (Request, Response, URL)
- 🔒 Type Safe - Full TypeScript type safety throughout
# Using JSR (recommended)
bunx jsr add @ninots/core
# Or using Bun directly
bun add @ninots/core
import { createApp } from '@ninots/core';
const app = createApp({
port: 3000,
development: true
});
app.get('/', (ctx) => {
return ctx.json({ message: 'Hello, NinoTS!' });
});
app.get('/users/:id', (ctx) => {
const { id } = ctx.params;
return ctx.json({ userId: id });
});
app.listen();
import { createApp, cors, logger, json } from '@ninots/core';
const app = createApp();
// Global middleware
app.use(logger());
app.use(cors());
app.use(json());
app.post('/api/users', (ctx) => {
const userData = ctx.body;
return ctx.status(201).json({ created: userData });
});
app.listen(3000);
import { Controller, Get, Post, Body, Param } from '@ninots/core';
@Controller('/api/users')
class UserController {
@Get('/')
async getUsers() {
return { users: [] };
}
@Get('/:id')
async getUser(@Param('id') id: string) {
return { user: { id } };
}
@Post('/')
async createUser(@Body() userData: any) {
return { created: userData };
}
}
import { createApp, errorHandler } from '@ninots/core';
const app = createApp();
app.use(errorHandler());
app.onError((error, ctx) => {
console.error('Custom error handler:', error);
return ctx.status(500).json({
error: 'Something went wrong!',
message: error.message
});
});
app.get('/error', () => {
throw new Error('This is a test error');
});
app.listen();
createApp(config?)
- Create new NinoTS applicationapp.use(middleware)
- Add global middlewareapp.get/post/put/delete/patch/head/options(path, handler, ...middlewares)
- Define routesapp.listen(port?, hostname?)
- Start serverapp.onError(handler)
- Set error handler
ctx.request
- Original Request objectctx.url
- Parsed URL objectctx.method
- HTTP methodctx.headers
- Request headersctx.params
- Route parametersctx.query
- Query parametersctx.body
- Request body (auto-parsed)ctx.json(data, init?)
- JSON responsectx.text(text, init?)
- Text responsectx.html(html, init?)
- HTML responsectx.redirect(url, status?)
- Redirect responsectx.status(code)
- Set status codectx.header(name, value)
- Set response header
cors(options?)
- CORS supportlogger()
- Request loggingjson()
- JSON body parsingerrorHandler()
- Error handlingrateLimit(options?)
- Rate limitingstaticFiles(directory)
- Static file serving
@Controller(basePath?)
- Define controller class@Get/@Post/@Put/@Delete/@Patch/@Head/@Options(path)
- HTTP methods@UseMiddleware(...middlewares)
- Apply middleware to route@Body()
- Inject request body@Param(key)
- Inject route parameter@Query(key?)
- Inject query parameter@Ctx()
- Inject full context
HttpStatus
- HTTP status code constantsMimeType
- MIME type constantsenv
- Environment variable helpersvalidate
- Validation utilitiesasync
- Async utilities (sleep, timeout, retry)object
- Object manipulation utilitiesstring
- String transformation utilities
MIT