# mexp

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

Latest version **0.0.9** (published 2017-06-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install mexp
pnpm add mexp
yarn add mexp
bun add mexp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2017-06-09 |
| First published | 2017-06-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Known vulnerabilities | 0 (+15 in 4 direct dependencies) |
| Install scripts | no |
| Author | 710335997@qq.com |
| Maintainers | maomaohou |

## Links

- npm: https://www.npmjs.com/package/mexp
- Repository: http://git.oschina.net/daoxiaozhang/mexp
- npm.io page: https://npm.io/package/mexp

## Dependencies (11)

- [ejs](https://npm.io/package/ejs.md) ^2.5.6
- [cors](https://npm.io/package/cors.md) ^2.8.3
- [mysql](https://npm.io/package/mysql.md) ^2.13.0
- [nconf](https://npm.io/package/nconf.md) ^0.8.4
- [helmet](https://npm.io/package/helmet.md) ^3.6.1
- [log4js](https://npm.io/package/log4js.md) ^1.1.1
- [morgan](https://npm.io/package/morgan.md) ^1.8.2
- [multer](https://npm.io/package/multer.md) ^1.3.0
- [express](https://npm.io/package/express.md) ^4.15.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.17.1
- [node-schedule](https://npm.io/package/node-schedule.md) ^1.2.1

## Recent versions

- 0.0.9 (latest) — 2017-06-09
- 0.0.8 — 2017-06-09
- 0.0.7 — 2017-06-08
- 0.0.6 — 2017-06-08
- 0.0.5 — 2017-06-08
- 0.0.4 — 2017-06-07
- 0.0.3 — 2017-06-07
- 0.0.2 — 2017-06-07
- 0.0.1 — 2017-06-07
- 1.0.0 — 2017-06-07

## 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接口列表

---
_Source: https://npm.io/package/mexp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
