- fork 模式下
- 使用命令参数
pm2 start app.js --node-args="--harmony"
- json 文件添加配置:
"node_args" : "--harmony"
- cluster 模式下
使用上一篇的方法require("babel-register");
在更改配置:
{
"apps": [
{
"name": "my_name",
"cwd": "./",
"script": "bin/start",
"instances" : "max",
"exec_mode" : "cluster",
"log_date_format": "YYYY-MM-DD HH:mm Z",
"error_file": "./logs/error.log",
"watch": ["routes"]
}
]
}
这里需要注意:
- exec_mode 要改为
cluster
, instances 为实例数, max 为 CPU 的核心数, - script 里配置的直接就是 js 文件,不需要加 node 命令(如 “script”: “node bin/start”) ,否则启动会报错,我踩过这个坑
留言