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 🙏

© 2026 – Pkg Stats / Ryan Hefner

swapjs-backend

v1.3.0

Published

A lightweight and modular Node.js framework

Downloads

8

Readme

Swap.js

Swap.js is a powerful and modern backend framework for Node.js, designed to offer a lightweight, efficient, and developer-friendly experience. With modular architecture, dependency injection, and middleware management, it allows you to create scalable backend applications with ease.

Table of Contents

Features

  • Lightweight and Fast: Designed for speed and simplicity.
  • Modular Architecture: Easily manage application modules.
  • Dependency Injection: Simplified management of services and dependencies.
  • Middleware Support: Customize requests with ease.
  • Routing Decorators: Use decorators like @Get and @Post for expressive routes.

Installation

To install Swap.js, ensure you have Node.js installed, then run:

npm install swapjs-backend

Quick Start Guide

Here’s a basic example of how to set up a simple Swap.js server:

  1. Initialize the Application

    const Swap = require('swapjs-backend');
    const app = new Swap.App();
    
    app.listen(3000, () => {
        console.log("Server running on port 3000");
    });
  2. Create a Controller

    Controllers define routes for your application. Here’s an example of a simple controller that responds to a GET request:

    const { Controller, Get } = require('swapjs-backend').decorators;
    
    @Controller('/api')
    class ExampleController {
        @Get('/hello')
        helloWorld(req, res) {
            res.send({ message: 'Hello, world!' });
        }
    }
    
    module.exports = ExampleController;
  3. Register the Controller in the App

    To make the controller active, register it with your app in the main file.

    const ExampleController = require('./controllers/ExampleController');
    app.registerController(ExampleController);
  4. Run the Server

    node index.js

    Visit http://localhost:3000/api/hello to see your first Swap.js response!

Core Concepts

App

The App class is the central part of Swap.js. It initializes and configures the server, registers routes, and handles incoming requests.

const app = new Swap.App();
app.listen(3000, () => console.log('Server running on port 3000'));

Router

The Router manages routes and provides path definitions. You can define routes using decorators within controllers.

Controllers

Controllers are classes that manage specific routes in your application. Define routes using decorators like @Controller for class-level routes and @Get, @Post, etc., for method-level routes.

Example:

const { Controller, Get } = require('swapjs-backend').decorators;

@Controller('/api')
class SampleController {
    @Get('/status')
    getStatus(req, res) {
        res.json({ status: 'active' });
    }
}

module.exports = SampleController;

Middleware

Middleware functions intercept requests and can be used for logging, authentication, or modifying requests and responses.

const authMiddleware = (req, res, next) => {
    if (req.headers.authorization) {
        next();
    } else {
        res.status(403).send('Unauthorized');
    }
};
app.useMiddleware(authMiddleware);

Example Project Structure

Here’s an example of a project structure for Swap.js:

project-root/
│
├── src/
│   ├── controllers/
│   │   └── ExampleController.js
│   ├── middlewares/
│   │   └── authMiddleware.js
│   ├── services/
│   │   └── ExampleService.js
│   ├── core/
│   │   ├── App.js
│   │   ├── Router.js
│   │   └── Middleware.js
│   └── index.js
│
├── package.json
└── README.md

License

This project is licensed under the MIT License.

NuggetsTeam