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

yasui

v1.4.0

Published

Light framework using Express for Node.js applications

Downloads

7

Readme

Yasui

Light framework using Express for Node.js applications.

(◠‿◠)やすいです!

Yasui can mean "easy" in Japanese. Yasui is meant to be easy to use, light, going to essentials only, with few dependencies. Yasui simplifies your life by providing you tools to quickly implement your controllers, middleware, endpoints, and your server. Yasui provides also complete errors management (logs and client responses) and logging service.

 

Get started

$ npm install yasui
import yasui from 'yasui';
yasui.createServer({ });

createServer will create an http server and listen it. Use yasui.createApp({ }), that return an express application, if you want to perform additional operations on it before listening the server and use your own listening method.

Browse the src/examples folder to get an example of a simple server using the basic features of Yasui.

 

Configuration

createServer and createApp takes a configuration object with the following parameters:

| Parameter | Description | | :-------- | :-----------| | controllers | An array containing your controllers (classes using the @Controller decorator). | | middlewares | An array containing your application level middlewares (classes using the @Middleware decorator). | | environment | The name of your environment. | | port | The listening port of your server (not needed in createApp). 3000 by default | | debug | Boolean, display logs more provided if true, and logs all incoming requests. | | apiKey | Authentication key for your API. If provided, all requests should contain the x-api-key header. |

 

Controllers

Yasui provides decorators to define your controllers and endpoints.

The Controller decorator takes in parameter the root path of its endpoints.

The methods of your controller can be decorated with the following: @Get, @Post, @Put, @Delete, @Patch. These take in parameter the relative path of the endpoint.

The parameters of your endpoint can be decorated with the following: @Res, @Req, @Next, to reflect express arguments, or with @Param, @Body, @Query, @Header to select a specific parameter from the query, or a subset of it ; they can take the name of the desired parameter as a parameter, in which case they will return the whole set.

@Logger also provides a query-specific timed logger service.

Example

import express from 'express';
import { Get, Controller, Res, Param } from 'yasui';

@Controller('/')
export class MyController {

    @Get('/:name')
    private hello(
        @Param('name') name: string,
        @Res() res: express.Response
    ): void {
        res.status(200).json({ message: `Hello ${name}!` });
    }
}

 

Middlewares

Yasui provides also decorators to define your middlewares like controllers and use its at application, controller, or endpoint level.

The Middleware decorator does not take parameter.

The parameters of your middleware can be decorated with the same decorators as controller endpoints.

Your middleware must obligatorily implement an use() method, which will define the execution function of it.

Example

import express from 'express';
import { logger, Middleware, Param, Next } from '..';

@Middleware()
export class HelloMiddleware {
    use(
        @Param('name') name: string,
        @Next() next: express.NextFunction
    ): void {
        logger.log(`Hello ${name}`);
        next();
    }
}
@Controller('/', HelloMiddleware)
// [...]
@Get('/:name', HelloMiddleware)
// [...]

 

Dependency injections

Not yet documented.

See src/examples folder for examples.