Webu.js
A web server framework for Node.js.
Installation
npm install webu.js
Usage
const fs = require('fs');
const path = require('path');
const Webu = require('webu.js');
const webu = new Webu();
webu.get('/', (req, res) => {
res.send(200, '<h1>Hello, World!</h1>', { 'Content-Type': 'text/html' });
});
webu.put('/update', (req, res) => {
res.send(200, 'Resource updated successfully!');
});
webu.get('/file', (req, res) => {
const htmlFilePath = path.join(__dirname, 'index.html');
fs.readFile(htmlFilePath, 'utf8', (err, data) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
});
});
webu.error((req, res) => {
res.send(404, '<h1>Custom 404 Error Page</h1>', { 'Content-Type': 'text/html' });
});
webu.start(3000, (port) => {
console.log(`Server listening on: ${port}`);
});
Features
- Simple and lightweight web server framework.
- Support for handling different HTTP methods, including GET and PUT.
- Easily set custom error pages for specific status codes.
- Customize the start message for the server.
Documentation
Handling HTTP Methods
Webu.js allows you to handle various HTTP methods such as GET, PUT, POST, DELETE, PATCH, HEAD, OPTIONS, and TRACE.
webu.get('/', (req, res) => {
});
webu.put('/update', (req, res) => {
});
Custom Error Pages
Set custom error pages to handle specific HTTP status codes. In this example, a custom 404 error page is set.
webu.error((req, res) => {
res.send(404, '<h1>Custom 404 Error Page</h1>', { 'Content-Type': 'text/html' });
});
Contributing
Feel free to contribute by opening issues or submitting pull requests. See CONTRIBUTING.md for more information.
License
This project is licensed under the ISC License - see the LICENSE file for details.