rapidfy-js
v1.0.2
Published
RapidfyJS is a simple and fast way to create a new project
Maintainers
Readme
🚀 RapidfyJS — Lightweight Node.js Web Framework
Fast, unopinionated, minimalist web framework for Node.js.
Table of contents
Introduction
RapidfyJS is a lightweight web framework built on the Node.js http core module. It supports middleware, routing, validation, file uploads, XML/JSON parsing, and multiple database integrations (MongoDB, MySQL, PostgreSQL).
Getting Started
To start using RapidfyJS, follow these steps:
📦 Installation
npm install rapidfy-jsCreate a new file, index.js, and copy the following code:
Or clone the example repository and run:
git clone https://github.com/KimmyLps/rapidfy-js-repo.git
cd rapidfy-js-repo
npm install🏗️ Basic Usage
const path = require('path');
const rapidfyJs = require('./src/core/Application');
// Create the app
const app = rapidfyJs();
const router = rapidfyJs.Router();
// ✅ Middleware: parse JSON, URL-encoded, XML, CORS, FormData
app.use(rapidfyJs.cors());
app.use(rapidfyJs.json());
app.use(rapidfyJs.urlencoded());
app.use(rapidfyJs.xml());
app.use(rapidfyJs.formData({
uploadDir: path.join(__dirname, 'uploads'),
maxFileSize: 10 * 1024 * 1024,
maxFiles: 5,
}));
// ✅ Basic route
router.get('/', (req, res) => {
res.json({ message: 'Welcome to RapidfyJS!' });
});
// ✅ Route POST + validation
router.post('/user', (req, res) => {
const result = req.validate(['body'], {
name: 'required|string',
email: 'required|email',
});
if (result.error) {
return res.status(400).json({
status: 'error',
message: 'Validation failed',
errors: result.errors,
});
}
res.json({
status: 'success',
data: result.validated,
});
});
// ✅ File upload route
router.post('/upload', (req, res) => {
res.json({
status: 'success',
message: 'File uploaded successfully',
files: req.files,
});
});
// ✅ Route for XML body
router.post('/xml', (req, res) => {
res.json({
message: 'Received XML data',
data: req.body,
});
});
// ✅ Mount router
app.use('/api/v1', router);
// ✅ Start server
app.listen(4000, () => console.log('🚀 RapidfyJS running on port 4000'));
- Initial the application
const app = rapidfyJs();- Define your routes and middleware functions:
app.get('/', (req, res) => {
res.send('Hello, World!');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});- Start the server by running
node app.jsin your terminal.
Features
🧱 Middleware Usage
JSON Parser
app.use(rapidfyJs.json());URL-encoded Parser
app.use(rapidfyJs.urlencoded());XML Parser
app.use(rapidfyJs.xml());CORS
app.use(rapidfyJs.cors());FormData / File Upload
app.use(rapidfyJs.formData({
uploadDir: path.join(__dirname, 'uploads'),
maxFileSize: 10 * 1024 * 1024,
maxFiles: 5,
fieldSize: 10 * 1024,
fields: 20,
}));💾 Database Integration
RapidfyJS supports multiple databases via dbManager.
MongoDB
await rapidfyJs.connectDB('default', 'mongodb', {
uri: 'mongodb://localhost:27017/mydb',
});
const db = rapidfyJs.mongoDB('mydb', 'default');
const users = await db.collection('users').find().toArray();
MySQL / MariaDB
await rapidfyJs.connectDB('main', 'mysql', {
host: 'localhost',
user: 'root',
password: '',
database: 'testdb',
});
const results = await rapidfyJs.query('SELECT * FROM users WHERE id = ?', [1], 'main');
PostgreSQL
await rapidfyJs.connectDB('pgdb', 'postgres', {
host: 'localhost',
user: 'postgres',
password: '',
database: 'testdb',
});
const results = await rapidfyJs.pgQuery('SELECT * FROM users', [], 'pgdb');🧩 Request Helpers
req.query
Access query parameters:
router.get('/search', (req, res) => {
res.json(req.query);
});req.params
Dynamic route parameters:
router.get('/users/:id', (req, res) => {
res.json({ userId: req.params.id });
});req.bearerToken()
Extract Bearer token from Authorization header:
router.get('/auth', (req, res) => {
res.json({ token: req.bearerToken() });
});req.basicAuth()
Extract Basic Auth credentials:
router.get('/basic', (req, res) => {
res.json(req.basicAuth());
});req.validate(sources, rules)
Validate request data:
const result = req.validate(['body'], {
name: 'required|string',
email: 'required|email',
});📤 Response Helpers
res.status(201).json({ message: 'Created' });
res.send('<h1>Hello</h1>');
res.json({ message: 'Hello' });
res.redirect('/login');
res.sendFile(path.join(__dirname, 'index.html'));🧠 Error Handling
The framework includes a global error handler by default. If a handler throws an error, it will be caught and returned in the standard JSON format.
Example response:
{
"status": "error",
"code": 500,
"message": "Something went wrong",
"data": null,
"metadata": null
}🧺 Example XML Body
Request:
<order>
<orderNumber>ORD-20251027001</orderNumber>
<customer>
<id>1001</id>
<name>Rabi’ah Nawakaning</name>
</customer>
<items>
<item>
<productId>501</productId>
<name>Notebook MSI Modern 15</name>
<quantity>1</quantity>
<price>25000</price>
</item>
<item>
<productId>502</productId>
<name>Wireless Mouse</name>
<quantity>1</quantity>
<price>600</price>
</item>
</items>
</order>Response:
{
"message": "Received XML data",
"data": {
"order": {
"orderNumber": "ORD-20251027001",
"customer": { "id": "1001", "name": "Rabi’ah Nawakaning" },
"items": {
"item": [
{ "productId": "501", "name": "Notebook MSI Modern 15", "quantity": "1", "price": "25000" },
{ "productId": "502", "name": "Wireless Mouse", "quantity": "1", "price": "600" }
]
}
}
}
}🏁 Run the Server
node app.jsDocumentation
For detailed documentation and examples, please refer to the RapidfyJS Documentation.
Contributing
We welcome contributions from the community! If you have any ideas, bug reports, or feature requests, please submit them to our GitHub repository.
License
RapidfyJS is released under the MIT License.
