A Node.js framework based on Alibaba's Egg.js


Keywords
egg, egg-framework
License
MIT
Install
npm install node-core@0.0.1

Documentation

简介

node-core 是一个基于 Egg.js 的 Node.js 服务端基础框架。

安装

$ npm install --save node-core

案例

一个完整的例子:链接

问题和建议

请提 issue:链接

已支持的插件

参考

使用方法

创建 articles model:

// app/model/articles.js
module.exports = app => {
  const {STRING, TEXT, INTEGER} = app.Sequelize

  return app.model.define('articles', {
    id: {
      type: INTEGER(8),
      primaryKey: true,
      autoIncrement: true,
      allowNull: false
    },
    author: {
      type: STRING(50),
      allowNull: true
    },
    title: {
      type: STRING(200),
      allowNull: false
    },
    subtitle: {
      type: STRING(200),
      allowNull: true
    },
    description: {
      type: TEXT('tiny'),
    },
    content: {
      type: TEXT('long'),
      allowNull: true
    },
    image: {
      type: INTEGER(8),
      allowNull: true
    },
    category_id: {
      type: INTEGER,
      allowNull: true
    }
  })
}

创建 articles service:

// app/service/articles.js
module.exports = app => {
  return class extends app.Service {
    constructor (ctx) {
      super(ctx)

      this.module = 'articles'
    }
  }
}

创建 articles controller:

// app/controller/articles.js
module.exports = app => {
  return class extends app.Controller {
    constructor (ctx) {
      super(ctx)

      this.module = 'articles'
    }
  }
}