LibServer is a minimalist library for creating HTTP servers in Node.js, offering a simplified alternative to Express.js, with no external dependencies. It is designed to be lightweight and efficient, making it easy to create servers, manage routes and middleware, and handle file uploads.
- HTTP Server: Easily create servers using Node.js's native
httpmodule. - Middleware: Support for both global and route-specific middleware.
- Dynamic Routing: Define routes for the main HTTP methods (
GET,POST,PUT,PATCH,DELETE). - Query Params: Automatic parsing of query string parameters.
- File Uploads: Native middleware for handling file uploads.
- JSON Support: Process requests and responses in JSON format.
Install the library via npm:
npm install lib-serverHere is a basic example of how to use LibServer:
import Server from 'lib-server';
const app = new Server();
app.use((req, res, next) => {
console.log(`Method: ${req.method}, Route: ${req.url}`);
next();
});
app.get('/hello', (req, res) => {
res.end('Hello, World!');
});
app.post('/upload', app.upload({ /* upload settings */ }), (req, res) => {
res.end('Upload successful!');
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});Adds a global middleware that will be executed for all requests.
Middleware for processing JSON requests and responses.
Middleware for handling file uploads. Options can be configured as needed.
Defines a route for the GET HTTP method.
Defines a route for the POST HTTP method.
Defines a route for the PUT HTTP method.
Defines a route for the PATCH HTTP method.
Defines a route for the DELETE HTTP method.
Starts the server on the specified port and runs the callback once the server is ready.
Contributions are always welcome! To contribute, please follow these steps:
- Fork this repository.
- Create a branch for your feature or bug fix.
- Implement your changes and, if possible, add tests.
- Submit a pull request describing your changes in detail.
Official repository: GitHub - MendoncaGabriel/lib-server
This project is licensed under the MIT License.
If you encounter any issues or have questions, feel free to open an issue on the repository.
For details about Performance Tests, click here.