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

express-dis

v1.0.2

Published

this is a express dependency injection server

Downloads

6

Readme

express-dis

基于 expresstypescript 的依赖注入服务器

特性

  • 实现依赖注入
  • 实现对象管理
  • 使用 typescript 的装饰器

安装

npm install express-dis

添加配置文件 edis.config.js 到项目根目录

// 这是个例子
module.exports = {
    // 是否跨域
    cors: true,
    // 扫描目录
    scanDirs: [
        "../../dist/example/controllers",
        "../../dist/example/providers"
    ]
}

或者运行的时候添加参数 --cfg 指定文件路径

node dist/example/test.js --cfg=src/example/edis.config.js

然后创建一个应用,例如:

import App from "express-dis";
import fileUpload from 'express-fileupload'
import path from 'path'

const app = new App()
// 添加静态资源目录
app.staticAssetsDir('/', '/abc')
app.staticAssetsDir('/xyz', '/123')
// 设置统一异常处理器
app.setErrorHandler((err, req, res, next) => {
    res.json({success: false, msg: err.message})
})
// 添加其他的参数解析器
app.addParser(fileUpload({
    limits: {fileSize: 10 * 1024 * 1024},
    useTempFiles: true,
    tempFileDir: path.join(__dirname, 'tmp'),
    defParamCharset: 'utf8'
}))
// 初始化
app.init().then(() => {
    app.listen(8080, () => {
        console.log('server start on: http://127.0.0.1:8080')
    })
})

注意: 必须在所有配置结束后使用 app.init 然后再使用 app.listen

装饰器

@router

添加 express 路由器

// url: 路由器地址
@router(url: string)

@get @post

添加 getpost 接口

// url: 路由地址
@get(url: string)
@post(url: string)

// 函数需要是异步的,例如
@get('/test')
public async test(){}

@provider

供其他类注入的类

// 没有参数
@provider

@inject

任意 @router@provider 的类中可以使用,用于注入其他 @router@provider 的实例对象

// className: 要注入的类名
@inject(className: string)

@middleware

@router 的类中可以添加

作用是添加中间件

// 没有参数
@middleware

// 函数需要是异步的,例如
@middleware
public async m(){}