npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lib-server

v1.2.1

Published

Uma biblioteca simples e leve para criar servidores HTTP em Node.js

Downloads

40

Readme

LibServer

LibServer is a lightweight HTTP server library for Node.js, designed as a simple alternative to Express.js. It has no external dependencies and provides features for routing, middleware management, and file uploads in a streamlined way.

Key Features

  • Minimal HTTP Server: Built on Node.js's native http module.
  • Middleware Support: Easily apply global or route-specific middleware.
  • Routing: Support for GET, POST, PUT, PATCH, and DELETE methods.
  • Query Parameters: Automatically parses query strings.
  • File Uploads: Simple file upload handling with size and format restrictions.
  • JSON Parsing: Native JSON request and response handling.

Installation

Install via npm:

npm install lib-server

Quick Start

Basic Example

Here’s how to create a simple server using LibServer:

import path from 'path';
import { Server } from 'lib-server';
import router from './routers.js';

const app = new Server();

// Middleware to handle JSON requests
app.use(app.json());

// Global middleware for logging requests
app.use((req, res, next) => {
  console.log(`Method: ${req.method}, URL: ${req.url}`);
  next();
});

// Define a GET route
app.get('/hello', (req, res) => {
  res.end('Hello, World!');
});

// Configure file upload
const uploadSettings = {
  format: '.png',
  path: path.resolve('storage'),
  maxFileSize: 1024 * 50 // 50 KB limit
};

// Define a POST route for file uploads
app.post('/upload', app.upload(uploadSettings), (req, res) => {
  res.end('Upload successful!');
});

// Use an external router for the /run route
app.root('/run', router);

// Start the server on port 3000
app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

export { app };

Using Routers

import { RootRouter } from 'lib-server';

const router = new RootRouter();

// GET route with query parameter
router.get('/test1', (req, res) => {
  const { queryParam } = req.query;
  res.send(`Test 1, queryParam: ${queryParam}`);
});

// GET route with dynamic parameter
router.get('/test2/:name', (req, res) => {
  const { name } = req.params;
  res.send(`Test 2, name: ${name}`);
});

// GET route with both query and dynamic parameters
router.get('/test3/:id', (req, res) => {
  const { id } = req.params;
  const { page } = req.query;
  res.send(`Test 3, id: ${id}, page: ${page}`);
});

export default router;

API Documentation

use(middleware)

Adds a global middleware function. Example:

app.use((req, res, next) => { 
  console.log('Middleware executed');
  next(); 
});

json()

Middleware for automatically parsing JSON payloads.

app.use(app.json());

upload(options)

Middleware for file uploads. Options include:

  • format: File format to allow.
  • path: Destination folder.
  • maxFileSize: Maximum file size (in bytes).
app.post('/upload', app.upload({ format: '.jpg', path: 'uploads/', maxFileSize: 1024 * 100 }), handler);

get(path, ...middlewares)

Defines a GET route. Example:

app.get('/hello', (req, res) => {
  res.end('Hello, World!');
});

post(path, ...middlewares)

Defines a POST route.

app.post('/data', (req, res) => {
  res.json({ message: 'Data received' });
});

put(path, ...middlewares)

Defines a PUT route for updating resources.

patch(path, ...middlewares)

Defines a PATCH route for partial updates.

delete(path, ...middlewares)

Defines a DELETE route for removing resources.

listen(port, callback)

Starts the server on a specific port and runs the callback function.

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and write tests (if possible).
  4. Submit a pull request explaining your changes.

Find the project repository here: GitHub - MendoncaGabriel/lib-server

License

This project is licensed under the MIT License. See the LICENSE file for more details.