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 🙏

© 2025 – Pkg Stats / Ryan Hefner

framework-services-es6

v0.1.27

Published

基于express的服务框架,加入了一些常用的中间件

Readme

使用说明

安装


npm install framework-services-es6

使用


const service = require("framework-services-es6")
service(option)

配置参数option


option={
    //当前服务端口
    serverPort: 3200,
    //日志存放目录
    logPath: "logs",
    //数据库连接设置
    db_settings: {
        mssql: {
            server: "127.0.0.1",
            user: "sa",
            pwd: "123456",
            database: "test"
        },
        redis: {
            server: "127.0.0.1",
            port: 6379,
            pwd: "123456",
            database: "test"
        },
        mongo: {
            server: "127.0.0.1",
            port: 27000,
            user: "root",
            pwd: "123456",
            database: "test"
        },
        mysql: {
            server: "127.0.0.1",
            port: 3306,
            user: "root",
            pwd: "123456",
            database: "test"
        }
    },


    //当前需要使用的数据库连接,可选项有:redis,mssql,mongo,sub
    //其中,sub 为redis的订阅服务,与redis连接共用一个redis连接配置
    dbs: ["redis", "sub"],
    //当前使用的中间件,会按顺序注入,务必注意调用循序
    /*可选项有
    	logger:日志组件
    	bodyParse,body格式化组件,但如果post文件的话不会进行格式化
    	cache:{缓存组件(未完成)
			rules:{不走缓存的path列表
                
                    path:{
                        enabled:是否缓存
                        timeout:缓存时间秒
                    }
                
                timeout:默认缓存时间,(所有不在rules中出现的path,都会缓存结果)
            }
    	}
    	debounce(debounce_mut):二选一,防抖组件,相同请求会等待上一次的结果来返回
    	proxy:{ 负载代理
			proxySource:{代理服务器配置
				请求的host:{
					targer:目标服务器
					paths:白名单
                    [
                        {
                            path:"路径",
                            repath:"替换路径" ,即,{path:"/a",repath:"/b"} 访问/a/xxx会变成 /b/xxx
                        }
                    ]
					unpaths:黑名单(优先)
					weight:权重,
                    healtCheck: 健康检查接口
				}
			}
    	}
		router:{自定义接口处理
            routerPath:"router所存放的目录"
        }
    	response:响应结果,走代理的话不会走到这里,
        timmer:{定时器构造,顺序随意,尽量放在最后
            timerPath:定时器放置位置
        }
    */
    middlewares:["logger","bodyParse","xmlparser",
	    {
	    	name:"cache",
	    	unpaths:[""]//不代理
	    },
	    "debounce",
	    {
	    	name:"proxy",
	    	proxySource:{
			    "127.0.0.1": [{
			        targer: "http://localhost:80",
			        paths: [{
                        name:"/pft",
                        repath:"/open"
                    }],//白名单
			        unpaths: [],//黑名单
			        weight: 10,
                    healtCheck: "test/index"
			    }],
			    "localhost": [{
			        targer: "http://localhost:30001",
			        paths: [],
			        unpaths: [],
			        weight: 10
			    }, {
			        targer: "http://localhost:30002",
			        paths: [],
			        unpaths: [],
			        weight: 30
			    }]
			}
	    },{
            name: "router",
            basePath:"api",
            routerPath: path.join(__dirname, "routers")
        }
	    "router","response",
        {
            name:"timmer",
            timerPath: path.join(__dirname, "timers")
        }
    ]
    // middlewares: ["logger", "bodyParse", "response"]
}

最近一次成功的配置文件范例


const path = require("path")
const service = require("framework-services-es6")
service.services({
  serverPort: 3200,
  logPath: "logs",
  middlewares: ["logger", {
    name: "bodyParse"
  }, "xmlparser", {
      name: "cache",
      rules: []
    }, "debounce", {
      name: "router",
      basePath: "api",
      routerPath: path.join(__dirname, "src", "routers")
    }, "response"],
  db_settings: {
    mongo: {
      server: "**********",
      port: 27017,
      user: "root",
      pwd: "123",
      database: "test-egg"
    }
  },
  dbs: ["mongo"],
})

版本变化

0.0.*

初始化项目,测试阶段

0.1.0

初步可用阶段

0.1.4

1.代理模式下,增加服务器存活判断

0.1.5

1.代理模式下,修正服务器存活判断的bug 2.防抖模式的way更换文字为“wait”

0.1.6

1.防抖事件监听最大数量设置为1000

0.1.7

1.修复定时器无效的bug

0.1.9

1.增加自定义中间件处理

 middlewares[(app)=>{
      app.use((req,res,next)=>{
         //do something
      })
 }]
 ```
## 0.1.12
1.增加日志判断,如果没有设置“logpath”的话,将会直接console.log打印

## 0.1.13
1.增加express-xml-bodyparser处理微信等xml数据


## 0.1.14
1.路由配置增加初始path


## 0.1.15
1.修正0.1.14的bug


## 0.1.16
1.http_handler 返回req与res,方便使用

## 0.1.17
1.修正url传参的bug

## 0.1.18
1.增加文件上传处理,在req.files中有文件实体

## 0.1.19
1.增加swagger处理(必须在router处理的前面)

## 0.1.20
1.增加httphandler前的处理

## 0.1.21
1.修正mongodb报错未处理的问题

## 0.1.22
1.调整响应结构,router只需返回正确结果,错误信息通过抛出异常来处理

## 0.1.23
1.调整0.1.22引起的防抖和缓存的问题

## 0.1.24
1.重新梳理逻辑,使得框架用户可以随时随地调用数据库方法

## 0.1.25
1.修正bug

## 0.1.26
1.修正bug