https://github.com/w3cdpass/replicax
Replicax - A lightweight, zero dependices, middleware, auto-reload support, HTTP server framework.
https://github.com/w3cdpass/replicax
express http-server node-js npm-package restapi restapi-backend
Last synced: 4 months ago
JSON representation
Replicax - A lightweight, zero dependices, middleware, auto-reload support, HTTP server framework.
- Host: GitHub
- URL: https://github.com/w3cdpass/replicax
- Owner: w3cdpass
- Created: 2025-07-27T14:26:34.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-07-27T15:32:54.000Z (10 months ago)
- Last Synced: 2025-10-29T02:22:21.335Z (7 months ago)
- Topics: express, http-server, node-js, npm-package, restapi, restapi-backend
- Language: JavaScript
- Homepage: https://replicax-page.vercel.app
- Size: 5.86 KB
- Stars: 6
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Replicax - A lightweight, zero dependices, middleware, auto-reload support, HTTP server framework



## Installation
```bash
npm i replicax --save
```
## 📚 Table of Contents
1. [🚀 Usage](#-usage)
2. [🔄 Auto Reload](#-auto-reload)
3. [📡 HTTP Methods](#-http-methods)
4. [🔑 Middleware](#-middleware)
5. [🔒 Ready for Production (HTTPS)](#-ready-for-production-https)
6. [🐞 Issues](#-issues)
7. [🤝 Author](#-author)
---
```javascript
const { replicax } = require('replicax');
const app = replicax();
// Simple GET route
app.get('/', (req, res) => {
res.json({ message: 'Hello from Replicax!' });
});
// Route with parameters
app.get('/users/:id', (req, res) => {
res.json({ userId: req.params.id });
});
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
```
---
## 2 🔄 Auto Reload
```json
// package.json
"scripts": {
"start": "replicax index.js"
},
```
#### [`/lib/watch.js`](./lib/watch.js) - File watcher that automatically restarts your server when `index.js` files change of your main project, with debouncing to avoid rapid restarts, ignores _node_modules_
---
## 3 📡 HTTP Methods
### GET
```javascript
app.get('/users', (req, res) => {
res.json({ users: getAllUsers() });
});
```
---
### POST
```javascript
app.post('/users', async (req, res) => {
const newUser = createUser(req.body);
res.status(201).json(newUser);
});
```
---
### PUT
```javascript
app.put('/users/:id', (req, res) => {
updateUser(req.params.id, req.body);
res.json({ success: true });
});
```
### PATCH
```javascript
app.patch('/users/:id', (req, res) => {
partiallyUpdateUser(req.params.id, req.body);
res.json({ updated: true });
});
```
---
### DELETE
```javascript
app.delete('/users/:id', (req, res) => {
deleteUser(req.params.id);
res.status(204).end();
});
```
### Route Chaining
```javascript
app.route('/articles/:id')
.get((req, res) => res.json(getArticle(req.params.id)))
.put((req, res) => res.json(updateArticle(req.params.id, req.body)))
.delete((req, res) => res.status(204).end());
```
---
### 4 🔑 Middleware
```javascript
// Authentication middleware
app.use('/admin', (req, res, next) => {
if (req.headers.authorization === 'secret') {
next();
} else {
res.status(401).json({ error: 'Unauthorized' });
}
});
```
### custom
```js
// define middleware
const authMiddleware = (req, res, next) => {
if (!req.headers.authorization) {
return res.status(401).json({ error: 'Unauthorized' });
}
next();
};
// use any where or a particular route
app.get('/protected', authMiddleware, (req, res) => {
res.json({ data: 'Secret data' });
});
```
---
### 5 🔒 Ready for Production (HTTPS)
```js
const fs = require('fs');
const { replicax } = require('replicax');
const app = replicax();
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
app.listen(443, () => {
console.log('HTTPS server running');
}, { https: true, httpsOptions: options });
```
---
# 🤝 Author
## GitHub: [@w3cdpass](https://github.com/w3cdpass)
## email : [kupasva663@gmail.com](mailto:kupasva663@gmail.com)