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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@t-box/server

v0.4.10

Published

A simple NodeJs server that uses controllers for routes.

Downloads

53

Readme

@t-box/server

The T-box server is a node server to handle website requests, its main purpose is to use attributes to define routes to be used by the server. The server works with controllers that are housed in a folder or set of folders and can be registered and the server will find them and process them into the system. The main benefit of this is to making new controllers and separating out different functionality in the site a little easier, some other things that the server allows is for injection so that different controllers can interact with each other without one not knowing about the other so that areas of the site can be sectioned off.

Features

  • Controller structure to simplify routes.
  • Easy attribute usage to register routes on the server.
  • Use of promises by the server to be versitile.
  • Simple parameters to try to parse out the body for easy translation from client to server.

Installation

NPM

    npm install @t-box/server

Yarn

    yarn install @t-box/server

Usage

The following is a simple usage of creating a server that will be listening on localhost:8080.

todo.controller.ts

    import { Controller, Route, Get, Post, Delete, Body } from '@t-box/server';
    import { TodoService, ITodo } from '../services/TodoService';

    @Route('todo')
    export class TodoController extends Controller {
        public constructor(private _service: TodoService) {
            super();
        }

        @Get()
        public search(term: string) {
            return this._service.todos.filter(x => term === undefined || term.length === 0 || x.name.startsWith(term));
        }

        @Get('{0}')
        public get(id: number) {
            let found = this._service.todos.filter(x => x.id === id);
            return found.length > 0 ? found[0] : null;
        }

        @Post('{0}/[action]')
        public done(id: number) {
            let found = this._service.todos.filter(x => x.id === id);
            if (found.length > 0) {
                found[0].done = true;
                return found[0];
            }
            return null;
        }

        @Post()
        public save(id: number, @Body todo: ITodo) {
            let found = this._service.todos.filter(x => x.id === id);
            if (found.length > 0) {
                found[0].done = todo.done;
                found[0].name = todo.name;
                return found[0];
            } else {
                return this._service.add(todo);
            }
        }

        @Delete('{0}')
        public remove(id: number) {
            return this._service.remove(id);
        }
    }

server.ts

    import { Application } from '@t-box/server';
    import { ServiceHandler } from './services/ServiceHandler';

    let app = new Application(__dirname, new ServiceHandler());
    async function boot() {
        await app.register('controllers');
        app.listen(8080);
    }

    boot()
        .then(() => { 
            console.log('Server started on http://localhost:8080');
        })
        .catch(err => {
            console.error(err);
            app.close(() => {
                process.exit();
            });
        });

API

You can read further by using the documentation, it will go into further detail on what options you have when creating the server and using it. Continue Reading

  • Development can be discussed in github issues, be sure to attach the server label.

License

@t-box/server is licensed under the MIT license.