Skip to content

Commit

Permalink
doc: add faq - how to start with pm2
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoshuai0102 committed Feb 13, 2017
1 parent 7111a9b commit 2b401ef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/source/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@ If you have questions that is not contained below, please check [egg issues](htt

Process management is very important. It defines the way we write code, meanwhile relates to deep runtime optimization. So we think it's better defined by framework itself.

## How to start application with PM2?

Although PM2 is not recommanded, you can use it anyway.

Firstly, put a start file in the root directory of your project:

```js
// server.js
const egg = require('egg');

const workers = Number(process.argv[2] || require('os').cpus().length);
egg.startCluster({
workers,
baseDir: __dirname,
});
```

We can start application with PM2 like this:

```bash
pm2 start server.js
```

19 changes: 19 additions & 0 deletions docs/source/zh-cn/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ title: 常见问题

进程模型非常重要,会影响到开发模式,运行期间的深度优化等,我们认为可能由框架来控制比较合适。

## 如何使用 PM2 启动应用?

尽管我们不推荐使用 PM2 启动,但仍然是可以做到的。

首先,在项目根目录定义启动文件:

```js
// server.js
const egg = require('egg');

const workers = Number(process.argv[2] || require('os').cpus().length);
egg.startCluster({
workers,
baseDir: __dirname,
});
```

这样,我们就可以通过 PM2 进行启动了:

```bash
pm2 start server.js
```

0 comments on commit 2b401ef

Please sign in to comment.