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

back-js

v1.0.0-beta

Published

<img alt="Back" title="Back" src="http://gdurl.com/58Bm" width="280" height="100">

Downloads

16

Readme

:sparkles: Back.js: MVC Framework for Node.js written in Typescript and built on top of Express.js :sparkles:

Build Status

back.js is a new MVC framework for node written totally in Typescript and inspired from the popular spring MVC in java, it has a system of dependency injection and it's easy to use. Back.js is very new, it's not ready for production yet and needs some contributions.

:star2: There are a lot of javascript frameworks for node.js out there. This one is different :

  • Provides great TypeScript developer experience
  • Simple and flexible API
  • MVC Architecture

Quick start

$ npm install -g back-starter

Create the app

$ back

Install dependencies

$ npm install

Start your app at http://localhost:3000/

$ npm start

Quick Tutorial

Example 1 (simple GET request):

import {Controller ,Get ,Route } from "back-js";

@Controller
@Route("/")
class HomeController{

    constructor(){}

    @Get("/")
    greet() {
        console.log("hello World");
    }
    
    @Get("/greet")
    anotherGreet() {
        console.log("another hello World");
    }
} 
  • @Controller : class Decorator used to mark the class as request handler.
  • @Route : class Decorator used to specify the route handled by the controller.
  • @Get : method Decorator, when used on a method ,this method will handle all the GET requests corresponding to its route.

in this example we created a controller HomeController that handles all requests coming from / route, inside the controller we have two methods greet and anotherGreet, these methods point to / and /greet respectively. We used @Get(route) to indicate that the method will handle any web request GET coming from the route specified in the Decorator.

Example 2 (Request ,Reponse and Route parameter):

import {Controller ,Get ,Post,Route ,Request ,Response } from "back-js";


@Controller
@Route("/product")
class ProductController{

    constructor(){}

    @Get("/:id")
    getProduct(req : Request ,res : Response, id : number) {
        console.log(id);
        // do something
        res.send("not found");
    }
    
    @Post("/")
    addProduct(res : Response,id : number, name : string, price : number){
        res.end("done");
    }

}

Here we have acontroller ProductController that points to /product route and has two methods getProduct and addProduct :

the first method getProduct has @Get("/:id") decorator on it, this means that it points to the /product/anything route .The route parameter in this case id can be accessed as a parameter of getProduct method. The req and res objects are the same as those in Express.js .

the second method addProduct points to the /product/ route and handles requests of type POST. it has four parameters the last three ones are id, name and price ,each parameter holds the value of the property that has the same name in the request body , fro example if the client send the object below :

{"id":12,"name":"nutella","price":20}

the result :

    @Post("/")
    addProduct(res : Response, id : number, name : string, price : number, other : string){
        console.log(id); // 12
        console.log(name); // nutella
        console.log(price); // 20
        console.log(other); // undefined
    }

Example 3 (@RequestBody, @ResponseBody, @Service):

   import {Controller,Service ,Get ,Post,Route ,Request ,Response, RequestBody, ResponseBody } from "back-js";
   
   class Product{
       constructor(
           private id : number,
           private label : string,
           private price : number,
       ){}
   }
   
   @Service
   class ProductService{
   
       constructor(){}

       getProduct() : Promise<Product>{
           return new Promise((resolve)=>{
               resolve(new Product(1,"Bimo",45));
           });
       }

   }
  
   @Controller
   @Route("/product")
   class ProductController{
   
       constructor(
           private productService : ProductService
       ){}

       @Get("/")
       @ResponseBody
       getProduct(req : Request ,res : Response ) : Promise<Product> {
           return this.productService.getProduct();
       }   

       @Post("/")
       @ResponseBody
       addProduct(@RequestBody product) : string{
           console.log(product);
           return "done";
       }
   } 
  • @Service : class Decorator used to indicates that the class is injectable
  • @ResponseBody : method Decorator , indicates that the method return value should be bound to the web response body (if the return value is a promise the data holded by this promise will be sent).
  • @RequestBody : parameter Decorator , indicates that the method parameter should be bound to the web request body

in this example we have a controllerProductController with one dependency productService that will be injected automatically by the framework,this controller has also two methods :

the first one getProduct it has @ResponseBody decorator on it and returns a promise this means that the value holded in the promise will be sent in the web response body.

the second one addProduct has @ResponseBody decorator on its parameter product this means that web request body will be bound to the product parameter.

Contribution

1- Fork

2- Do your magic

3- pull request :smile:

License

MIT