Efrix.js
Efrix.js is a lightweight Node.js web framework for creating simple HTTP servers with built-in request and response handling, logging, and static file serving.
Features
- Lightweight and fast
- Supports GET, POST, PUT, and DELETE requests
- Auto-redirect to localhost
- Logging system
- Request limits
- Static file serving support
Installation
npm install efrix
Usage
Basic Example
const { App } = require('efrix');
const app = new App({ port: 3000, autoRedirect: true, logs: { enabled: true }, static: 'public' });
app.Get('/', (rq, rs) => {
rs.send('Hello, world!');
});
app.Post('/data', (rq, rs) => {
rs.json({ received: rq.body });
});
app.Put('/update', (rq, rs) => {
rs.json({ message: 'Resource updated' });
});
app.Delete('/delete', (rq, rs) => {
rs.json({ message: 'Resource deleted' });
});
Static File Serving
Efrix.js supports serving static files from a specified directory.
const app = new App({ port: 3000, static: 'frontend' });
Place your static files (HTML, CSS, JS) in the frontend
folder. The server will automatically serve them when requested.
Options
Option | Type | Default | Description |
---|---|---|---|
port |
Number | 3000 |
Server port |
autoRedirect |
Boolean | false |
Auto-redirect to http://localhost:port |
logs.enabled |
Boolean | false |
Enable error logging |
logs.dir |
String | ./logs/errors.log |
Log file directory |
maxRequests |
Number | null |
Maximum allowed requests per session |
maxReqTime |
Number | null |
Maximum time (ms) before request timeout |
static |
String | null |
Directory for serving static files |