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

springpress

v1.3.3

Published

Express.js top-level MVC framework feel like Spring Boot

Downloads

14

Readme

Springpress

A Top-level framework of Express.js for developing clean architecture API service, especially on TypeScript.

Springpress provides basic Express.js functions and MVC utilities related out of the box. Let you deep-dive into the world of OOP and the scent of our motivation, Spring Boot with Springpress.

Installation

Node.js 16.15.0 (LTS) is required

Using npm:

$ npm install springpress

Using yarn:

$ yarn add springpress

Usage

Assume you are creating a dog controller that sends a response of the dog's name when requesting to /dog/name.

Server

First, you need to create a main class that extends Springpress class. This class will store all of your things. e.g. services, controllers, repositories initialization.

import { Springpress } from 'springpress';

class ExampleServer extends Springpress {

  public onStartup(): Promise<void> {
    // This code will run when your start your application.
    // All of initialization should do it here.
  }

}

Don't forget to call Springpress#listen to bind to and to listen for conections. This method returns an http.Server object (the built-in HTTP module). You can use this instance in your testing framework to work with HTTP.

const port = 3000; // you can specify whatever port you want :)
const exampleServer = new ExampleServer(port);
exampleServer.listen();

Controller

Controller Mapping

Easily define your controller with @ControllerMapping decorator:

@ControllerMapping('/dog') // <-- Decorator here!
class DogController extends Controller {
  // Routes implementation will be here.
}

The @ControllerMapping decorator will mount your class on a router with the path where you specified in the first decorator parameter. In this case, this class will be mapped with /dog on the router.

  • A client can connect by http://localhost:3000/dog/ followed by your implemented route. (port 3000 is just an example)
  • On this step, you will not actually be able to access it. You need to implement a route first by following the next step.

Route Mapping

Easily define your route with @RouteMapping decorator:

@ControllerMapping('/dog')
class DogController extends Controller {

  @RouteMapping('/name', Methods.GET) // <-- Decorator here!
  private async getName(req: Request, res: Response) {
    res.status(200).json({
      name: 'Doge',
    });
  }

}

The @RouteMapping decorator will mount your decorated method as a routing destination of an HTTP request in a controller.

A RouteMapping parameter

  • path - a string of route path
    • It can be anything that Express.js routing support
  • method - an enum of HTTP method (You can use Methods imported from Springpress)

Now, your client will see http://localhost:3000/dog/name and get a response like below in a JSON format.

{
  "name": "Doge"
}

Controller Registration

Everything above in the Controller section will not work if you haven't registered the controller in the Server class.

import { Springpress } from 'springpress';
import { DogController } from './controllers/DogController';

class ExampleServer extends Springpress {

  public onStartup(): Promise<void> {
    // Don't forget here!
    const controllerRegistry = this.getControllerRegistry();
    controllerRegistry.register(new DogController());
  }

}

Contribution

There are many ways in which you can participate in this project, for example:

License

Copyright (c) Vectier. All rights reserved.

Licensed under the MIT license.