搭建egg项目
快速生成项目(npm >=6.1.0):
$ npm init egg --type=simple
$ npm i
启动项目:
$ npm run dev
$ open http://localhost:7001
连接mysql数据库
安装插件 egg-mysql :
$ npm i --save egg-mysql
开启插件:
// config/plugin.js
module.exports = {
mysql: {
enable: true,
package: 'egg-mysql',
},
};
配置各个环境的数据库连接信息:
// config/config.default.js
exports.mysql = {
// 单数据库信息配置
client: {
// host
host: '127.0.0.1',
// 端口号
port