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

mexp

v0.0.9

Published

基于Express开发的Rest接口快速开发框架

Downloads

14

Readme

基于Express搭建的Rest接口开发框架

基于Express开发的接口服务开发框架 用于快速开发接口、采用sql model配置文件的形式加载接口

依赖:

  • mysql
  • express
  • bodyParser
  • cors
  • helmet
  • morgan

使用

安装

npm install mexp --save

使用

//index.js

var mexp=require('mexp');

//注册配置文件	
mexp.config({path,name});

//注册model
mexp.model(dirString);

//注册路由
mexp.route(function(app){app.use('/')});

//启动服务	
mexp.boot()    

启动项目

node index.js

API

#### config(params):加载配置文件

param:[String|Object]

String:目录扫描

Object{path,name}:文件地址、和文件名称

model(params):加载model配置文件

params:String model配置文件的目录、系统会自动扫描下面的文件

[暂时] route(params):回调的形式传回app对象

params:Function

回调参数:express实例对象

cors(...[params1,params2]):启用cors配置

safe():启动默认的安全配置

boot():启动服务

model配置说明:

现在基于文件名称来区分业务模块:user.json

{
	key:{
            name:"接口名称",
            sql:"sql字符串",
            path:"",
            query:""
        }
}

key 接口前缀路径,如:GET#/user

name 接口名称、非必填项

sql sql字符串、必填

path 路径查询字段数组、非必填项

query url查询字段数组、非必填项

Demo

目录结构:

Project

	configs

		--database.json

	models

		--modelA.json		

	--index.js

	--package.json

安装mexp

npm install mexp --save

代码:

var path = require("path");
var mexp = require("mexp");

var dir = path.resolve(__dirname, './models');
var file = path.resolve(__dirname, './configs/database.json');

mexp.model(dir);
mexp.config({ path: file, name: "database" });


mexp.route(function (app) {
	app.use('/test', function (req, res) {
    	res.json({message:"hello"});
	});
});

mexp.boot();

启动项目:

node index.js --port 3000

访问:

http://localhost:3000

可以看到可用的api接口列表