node_egg框架项目部署_目录结构

// 快速初始化egg项目
// 创建egg目录,并且打开到egg,可省略
$ mkdir egg-example && cd egg-example

// 脚手架生成egg项目
$ npm init egg --type=simple
// 安装报错
  error code ENOLOCAL
  error Could not install from "Files\nodejs\node_cache\_npx\18476" as it does not contain a package.json file.
// 解决方案:
  “更换node cache 路径”在项目目录下面运行:
  #npm config set cache "C:\Users\登录windows的用户名\AppData\Roaming\npm-cache"--global
  目录和“--global”之间没有空格。

// 安装项目依赖
$ npm i

// 启动项目:
$ npm run dev
$ open http://localhost:7001


// 目录结构
egg-project
├── package.json
├── app.js (可选)                  // 用于自定义启动时的初始化工作
├── agent.js (可选)                // 用于自定义启动时的初始化工作
├── app
|   ├── router.js                  // 用于配置 URL 路由规则
│   ├── controller                 // 用于解析用户的输入,处理后返回相应的结果,
│   |   └── home.js
│   ├── service (可选)             // 用于编写业务逻辑层
│   |   └── user.js
│   ├── middleware (可选)          // 用于编写中间件
│   |   └── response_time.js
│   ├── schedule (可选)            // 用于定时任务
│   |   └── my_task.js
│   ├── public (可选)              // 用于放置静态资源 index.html, css, img .....
│   |   └── reset.css
│   ├── view (可选)                // 用于放置模板文件
│   |   └── home.tpl
│   └── extend (可选)              // 用于框架的扩展
│       ├── helper.js (可选)
│       ├── request.js (可选)
│       ├── response.js (可选)
│       ├── context.js (可选)
│       ├── application.js (可选)
│       └── agent.js (可选)
├── config 
|   ├── plugin.js                  // 用于配置需要加载的插件
|   ├── config.default.js          // 用于编写配置文件
│   ├── config.prod.js
|   ├── config.test.js (可选)
|   ├── config.local.js (可选)
|   └── config.unittest.js (可选)
└── test                           // 单元测试
    ├── middleware
    |   └── response_time.test.js
    └── controller
        └── home.test.js 
posted @ 2020-03-21 00:18  前端之旅  阅读(1041)  评论(0)    收藏  举报