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

naily

v2.3.0

Published

写了一个没有模块系统的 Minimal Nest.js 写着玩的~

Downloads

11

Readme

Naily(Nai Core)

基于 Express 实现了一个简易的,无模块系统的 Nest.js。

自动依赖注入特性+无模块系统,企业级开发就算啦,写着玩的,代码写得很垃圾。

使用

只支持 TypeScript,没去特别适配 JavaScript 和 Babel 转译器。如果使用有问题别问我(

安装

需有node^12 + pnpm环境,然后运行 cli 命令:

pnpx naily

一个简单的小示例

main.ts

// 注入你写的控制器
// 必须在导入app对象之前导入 才能被检测到并挂载
import "./main.controller";
// 所有控制器导入之后再导入此装饰器!
import { BootNailyApplication, type CanBoot, IMount } from "../src/app";

@BootNailyApplication
export class Booter implements CanBoot {
  // 实现了main函数
  main(app: IMount): void {
    app.boot(8000);
  }
}

app
  // 使用useMiddleware创建中间件
  .useMiddleware((req, res, next) => {
    // 这里编写您的中间件...
  })
  // 使用useFilter将在全局挂载Filter
  .useFilter(MyFilter)
  // 最后使用boot启动服务器
  .boot(8000);

main.controller.ts

// 导入控制器注解和GET方法注解
import { GetMapping, RequestIp, RestController } from "naily";
// 导入一个服务
import { AppService } from "./main.service";

// 这里导出一个类 用controller装饰起来~
@RestController()
export class AppController {
  // 这里注入一个服务~
  constructor(private readonly appService: AppService) {}
  // 这里用get装饰起来~
  @GetMapping()
  // 使用@RequestIp可以获取到请求发出地的IP地址哦
  public getHello(@RequestIp ip: string) {
    // 返回一个JSON对象吧
    return {
      ip: ip,
      data: this.appService.getData(),
      message: "Hello world",
    };
  }
}

main.service.ts

import { Injectable } from "naily";

// 使用Injectable标记这是一个可以被注入的类
// 说人话就两个字:服务
@Injectable
export class AppService {
  // 随便弄个方法
  getData() {
    return 200;
  }
}

装饰器列表

| 装饰器 | 说明 | | ---------------- | --------------------------------- | | RestController | 控制器 标识一个控制器必须要用这个 | | GetMapping | 标识 GET 方法装饰器 | | PostMapping | 标识 POST 方法装饰器 | | OptionsMapping | 标识 Options 方法装饰器 | | PutMapping | 标识 Put 方法装饰器 | | PatchMapping | 标识 Patch 方法装饰器 | | DeleteMapping | 标识 Delete 方法装饰器 | | RequestMapping | 匹配所有方法装饰器 | | RequestQuery | 获取 URL Query 装饰器 | | RequestParam | 获取 URL Param 装饰器 | | RequestBody | 获取 URL Body 装饰器 | | RequestIp | 获取 Ip 地址 装饰器 | | UseFilter | 使用错误过滤器 | |

错误过滤器

参考test/main.filter.ts

感谢