eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.88k stars 1.81k forks source link

eggjs怎么以单进程方式启动? #3559

Closed logzh closed 5 years ago

logzh commented 5 years ago

eggjs 2.15.0 + 增加了单进程模式支持,请问具体怎么以单进程方式启动?有文档吗?

相关环境信息

LuoShiXi commented 5 years ago

@logzh 可以参考 egg-script start --workers=1 https://github.com/eggjs/egg-scripts#command, 不知道是不是这个

logzh commented 5 years ago

@LuoShiXi

参考:https://github.com/eggjs/egg/issues/3180

egg.js 2.15.0 开始增加的功能:support single process mode

// index.js
const egg = require('egg');

egg. start({
  baseDir: __dirname,
});

执行命令:

node index.js

不过还不能用在生产环境,有warn提示:

single process mode is still in experiment, please don\'t use it in production environment
lihaonanGY commented 5 years ago

使用node index.js 成功跑起来,也输出了提示single process mode is still in experiment, please don\'t use it in production environment 然后eggcore egg logger mongoose security也都起来了

但是并没有端口可以访问到该服务?

const egg = require('egg');

egg. start({
  baseDir: __dirname,
});
node index.js
ronesam commented 4 years ago

关键参考: https://cloud.tencent.com/document/product/583/37278

搜遍全网,终于解决了。 这里记录一下阿里云Severless(CustomRuntime) + Nas的调用方式:

boostrap(需要可执行权限)

#!/bin/bash
path=/mnt/**/alpha/  # `**`内填写函数计算服务绑定的Nas地址
export EGG_HOME=$path # 一定要写这个环境变量, 否则会报错
export EGG_SERVER_ENV=alpha # 指定env
node $path/index.js

index.js


'use strict';
const egg = require('egg');

egg.startCluster({ baseDir: __dirname, mode: 'single', port: 9000 })

heartJJ commented 2 years ago
'use strict';
const egg = require('egg');

const main = async () => { 
  const app = await egg.start({
    baseDir: __dirname,
  });

  app.listen(7001); // 端口
  console.log(`Server started on ${7001}`);
};

main();