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

bitter-press

v1.0.30

Published

better express.js experience

Downloads

4

Readme

image

BitterPress

Short Brief

It seems like you're encountering some challenges when trying to use TypeScript with Express, and you're looking for a solution that provides more structure and takes advantage of TypeScript decorators. One solution that fits this description is BitterPress.

BitterPress is a framework for building efficient, scalable, and maintainable server-side applications. It is built on top of Express and uses TypeScript as its primary language. BitterPress provides a structured, object-oriented approach to building applications, making it a great fit for developers who prefer a more organized and modular codebase.

Features

BitterPress focuses on providing decorators for Express.js API logic abstraction with the added benefit of a simple built-in dependency injection container for a lightweight and minimalistic approach to TypeScript development.

Warning :

This repository is still heavily in development proccess, so there may be many bugs.

  • Controllers
  • Route, Query, Body, Params
  • Request
  • Response
  • Change Response Status Code
  • Set Headers
  • Middleware Support
  • Services
  • Dependency Injection based
  • Lifecycle hooks
  • Instance of express

Installation

Remove npm section for now.

Next, generate the tsconfig.json file at the root level of your project by running tsc --init, and within the compilerOptions object, include the following options:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Now you are ready to go.

@SetupApp Decorator

You can use a custom middleware with the SetupApp decorator, set the server's port, or use a specific controlle, also you can define a custom provider

import { SetupApp, Controller, useGlobalMiddlewares, customProdivers } from 'bitter-press';

@SetupApp({
  port: 3000,
  controller: [],
  useGlobalMiddlewares: [],
  customProdivers: [],
})
export class ExampleAppModule {}

Http Methods

This framework supports classic HTTP methods and provides decorator-based support as well.

import { SetupApp, Controller } from 'bitter-press';

@Controller('/auth')
export class ExampleController {
  @Get(':id')
  public async getSpecificUser() {
    return 'CANMERTINYO!';
  }

  @Post('/register')
  public async register() {
    return 'registered!';
  }

  @Delete()
  public deleteUser() {
    return 'success';
  }
}

And you can use other methods like: patch, update, put ...etc

Custom Providers

In addition to registering services, BitterPress allows you to define custom providers that can be injected into your application. These custom providers can be associated with string tokens or redefine what is injected, replacing class instances by using class tokens.

To define custom providers, you should specify them within the @SetupApp decorator at the root level of your application. The customProviders property in the @SetupApp decorator's properties object is used to hold an array of these providers.

For each custom provider, two main aspects need to be defined:

Token: This specifies the identifier for the provider and can be either a string or a constructible type (class reference).

Instance: This is the actual object that will be injected when the token is used.

import { SetupApp, Controller, useGlobalMiddlewares, customProdivers } from 'bitter-press';

@SetupApp({
  port: 3000,
  controller: [],
  useGlobalMiddlewares: [],
  customProdivers: [{ token: ExampleService, instance: new ExampleService() }],
})
export class ExampleAppModule {}

Life Cycle Hooks

I was heavily inspired by the Vue.js framework while creating these hooks, and I integrated them into this framework.

Current available hooks:

  • BeforeGlobalMiddlewaresBound
  • AfterGlobalMiddlewaresBound
  • BeforeRoutesBound
  • AfterRoutesBound
  • BeforeListenStarted
  • AfterListenStarted

I want to explain my hooks without going into too much detail,

@BeforeGlobalMiddlewaresBound

the hook represents the portion that will be executed before middleware is defined in the application. If you have such operations, this hook can be beneficial for you.

@AfterGlobalMiddlewaresBound

The hook represents the code that will be executed after middlewares have been applied in the application.

@BeforeRoutesBound

The hook represents the operations that will be executed before routes are defined. If you want to run your code before defining routes, you should use this hook.

@AfterRoutesBound

The hook represents the operations that will be executed after routes have been defined.

@BeforeListenStarted

The hook represents the operations that will be executed before your server is started.

@AfterListenStarted

The hook represents the operations that will be executed after your server has started running.

Some Examples About Life Cycle Feature


  @BeforeGlobalMiddlewaresBound()
  private beforeGlobalMiddlewaresBound() {
      console.info('I am executed just before middlewares are bound');
  }

  @AfterGlobalMiddlewaresBound()
  private afterGlobalMiddlewaresBound() {
      console.info('I am executed just after middlewares are bound');
      this.expressApp.use(express.urlencoded());
  }

  @BeforeListenStarted()
  private beforeListenStarted() {
    console.log('I am executed just before server are bound')
  }

  @AfterListenStarted()
  private afterListenStarted() {
    console.log('I am executed just after server are bound')
  }

 @BeforeRoutesBound()
  private beforeRoutesBound() {
    console.log('I am executed just before routes are bound');
  }

  @AfterRoutesBound()
  private afterRoutesBound() {
    console.log('I am executed just after routes are bound');
  }