mskv-server-creater-kit
v1.0.0
Published
A lightweight Node.js server framework with routing, middleware, static file serving, and more.
Maintainers
Readme
MSKV Server Creator Kit
A lightweight Node.js server framework for rapid development, featuring routing, middleware, static file serving, and more.
Author
Name: Muhammed Sinan K V
GitHub: (https://github.com/mskv17)
Email: [email protected]
Features
- Routing (GET, POST, PUT, DELETE)
- Router grouping
- Middleware support
- Static file serving
- CORS support
- File system utilities
Getting Started
const app = require('./index')();
app.listen(3000);API Reference
ServerCreater Methods
get(route, callback): Register a GET routepost(route, callback): Register a POST routeput(route, callback): Register a PUT routedelete(route, callback): Register a DELETE routerouter(prefix, callback): Group routes under a prefixuse(middleware): Add middlewarestatic(route, folder): Serve static filescors(urls): Enable CORSlisten(port, callback): Start the server
Request Object
url: Request URLbody(): Async function to get request bodymethod: HTTP methodheaders: Request headersquery: Query parameterscookies: Cookies
Response Object
send(string, status): Send plain text responsesendFile(path, file, status): Send file responsejson(data, status): Send JSON responseredirect(route, status): Redirect responseheader(header): Set custom headercookie(name, value, options): Set cookie
Examples
Basic Server
const app = require('./index')();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000);Router Grouping
app.router('/api', (router) => {
router.get('/users', (req, res) => {
res.json([{id:1, name:'Alice'}]);
});
});Static Files
app.static('/public', './public');Middleware
app.use((req, res, next) => {
console.log(req.method, req.url);
next();
});License
MIT
