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

ruserver

v1.2.6

Published

Biblioteca feita com o express para criar um servidor de forma mais simples e rápida, com suporte a decorators e controllers.

Downloads

33

Readme

Biblioteca de Express para criar um servidor basico e configurado.

Importante

Esta biblioteca está em desenvolvimento, então pode conter bugs e não está completa. Baixe sempre a ultima versão, pois ela pode conter correções de bugs e novas funcionalidades. E fique de olho no README, pois ele pode conter informações importantes.

Sobre

Biblioteca RuServer de Ruan Fernandes. Feita em cima do Express, ela facilita a criação de um servidor basico e configurado com controladores. Ela usa Controllers para facilitar a criação de rotas e ações.

REPOSITÓRIO:

DOAÇÕES:

Como usar

Para usar a biblioteca, basta instalar ela com o comando:

npm i ruserver

Depois, basta importar a biblioteca no seu arquivo.ts

import { RuServer } from 'ruserver';
import { HelloWorld } from './HelloWorld';

const server = new RuServer(3000); // Porta do servidor (Opcional)
server.loadControllers([HelloWorld]);
server.start();

E criar um controller com o nome desejado, no meu caso HelloWorld.ts

// # Path: HelloWorld.ts
import { Controller, Get, Post, RequestData, Logger, Ok, BadRequest } from 'ruserver';
@Controller()
export class HelloWorld {
   
    constructor() {
        console.log('TestController created');
    }

    // Sem primeiro parametro, o método é chamado para o caminho "/"
    @Get('', 'Descricao do metodo')
    index(requestData: RequestData, extraParams: Map<string, any>) {
        // requestData e logger são injetados automaticamente
        // Não é necessário declarar os parâmetros, somente se precisar usa-los
        const Logger: Logger = extraParams.get("logger");

        Logger.info("TestController.index() called");

        // requestData.query é um objeto com os parâmetros da query string
        if (requestData.query.name) {
            return new Ok('Bem vindo ' + requestData.query.name);
        }

        // Tipos de Retorno Ok(data), Unauthorized(data), BadRequest(data), InternalError(data), NoContentOK(data)
        return new Ok('Bem vindo ao servidor');
    }

    @Get('test/:id')
    test(requestData: RequestData) {
        // requestData.params é um objeto com os parâmetros da URL
        return new Ok(`Test ${requestData.params.id}`);
    }

    @Post()
    post(requestData: RequestData) {
        if (!requestData.body.name) {
            return new BadRequest(`Name is required`);
        }

        // requestData.body é um objeto com os parâmetros do corpo da requisição
        return new Ok(`Post ${requestData.body.name}`);
    }
}

API

Após tudo feito, basta iniciar as requisições nas rotas criadas.

TODO

  • [x] Criar biblioteca
  • [x] Criar documentação
  • [x] Criar exemplos
  • [x] Criar função para modificar o status code da resposta
  • [x] Criar função para modificar o cabeçalho da resposta
  • [x] Criar função para modificar o corpo da resposta
  • [ ] Criar função para autenticar o usuário

Exemplos

  • [x] Criar um servidor basico
  • [x] Criar um servidor com controladores
  • [ ] Criar um servidor com autenticação
  • [ ] Criar um servidor com banco de dados