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

autoserverw

v1.0.13

Published

#### 快速开始

Downloads

44

Readme

快速搭建api访问

快速开始

1. 创建目录结构
- config
 |- test.json
- src
 |- hooks
   |- test
     |- index.js
 |- schema
   |- mongo
     |- test.js
 |- app.js
- package.json
  • config: 下主要放置配置文件,具体文件名称将根据NODE_ENV来决定调用(如NODE_ENV=test,那么程序启动时将进行调用test.json)
  • src: 项目文件存放位置
  • hooks: 存放路由中间件 存放要求,与schema中定义的名称一致,程序将自动查找对应的中间价进行加载
  • schema: 实体类存放地址,下面有使用mysql / mongo 目录进行区分实体对象所对应的库
  • app.js: 启动文件
2. 创建实体对象

这里我们使用mysql作为我们的数据库

在src-schema-mysql 下创建文件 test.js

'use strict';

var schema = {
  id: {build: (t) => t.increments('id').comment('id'), type: Number, primarykey: true},// primarykey 用于标注删除和查询时的对象属性
  name: {build: (t) => t.string('name'), type: String, notnull: true}, // notnull 用于标注该字段在接口post调用时为必填字段
  age: {build: (t)=> t.integer('age'), type: Number},
  cid: {build: (t) => t.string('cid').comment('身份证'), type: String, notnull: true, put: false, patch: false}, //put / patch: false 则表示当前属性将无法通过put和patch进行修改
  //使用mysql时,程序将自动追加createdat(创建时间)和updatedat,修改时间
}

module.exports = {
  schema,
  name: 'test',
  router: ['all']
}

在实体类中如果设置了router,并赋值,程序将自动创建对于的接口

| 属性 | 值 | | :----: | :------------------------------------ | | router | all, get, getByKey,put, patch, delete |

自动生成的接口格式为 /v1/[schema.name] (接口将在name后自动追加s,如已有s则不在追加,如实体对象test,name为test,则接口为 /v1/tests)

3. 设置配置文件 config
{
  "port": 3000,
  "default": {
    "mysql": "mysqlapi"
  },
  "mysqlapi": {
    "client": "mysql",
    "connection": {
      "host": "127.0.0.1",
      "port": "3306",
      "user": "user",
      "password": "password",
      "database": "testapi"
    },
    "pool": {
      "min": 10,
      "max": 225
    }
  },
  "mysqls": ["mysqlapi"]
}
  • port: 启动程序时的端口号
  • default: 默认配置所对应的属性名
  • mysqlapi: 具体mysql的相关配置,名称自定,需要在mysqls中正式启动
  • mysqls: 配置的mysql配置参数进行启动与初始化

实例 app.js

'use strict';

// 快速启动
let app = require('autoserverw');

package.json 修改scripts进行启动项目

{
  "scripts": {
    "test": "NODE_ENV=test node ./src/app.js"
  }
}
# 启动项目
$ npm run test