【问题标题】:How to run React Boilerplate with forever如何永远运行 React Boilerplate
【发布时间】:2018-08-12 16:50:05
【问题描述】:
我将永远在服务器中运行react-boilerplate 应用程序。
我找到了forever,但我不确定如何将参数传递给永远。运行服务器的命令如下:
PORT=80 npm run start:production
似乎forever start PORT=80 npm run start:production 对我没有帮助。
【问题讨论】:
标签:
javascript
node.js
deployment
forever
react-boilerplate
【解决方案1】:
有一件事是PORT=80部分是设置环境变量,这种命令应该在其他命令之前。另一件事是,要永远运行 npm 脚本,你需要使用不同的语法,所以PORT=80 forever start -c "npm run start:production" /path/to/app/dir/。
如果您从项目文件夹中永久运行,则路径应为 ./
【解决方案2】:
或者您可以使用 pm2 或 nohup
运行一个反应应用程序
1) 全局安装 pm2
npm install pm2 -g
2) 导航到项目文件夹并执行,后面需要空间--
pm2 start npm -- start
3) 查看正在运行的实例
pm2 ps
4) 查看其他选项
pm2 --help
使用 nohup 运行
1) 导航到项目文件夹
nohup bash -c 'npm start' &
【解决方案3】:
pm2 是出色的 Node.js 生产流程管理器。除了启动和守护任何应用程序之外,它还有一个内置的负载均衡器。
安装 pm2:
npm install pm2 -g
要向您的应用添加启动和守护进程,请导航到应用文件夹并:
pm2 start app.js
在服务器重启时使 pm2 自动启动:
$ pm2 startup
然后复制并粘贴生成的代码。
【解决方案4】:
步骤 01:npm intsall -g 永远
然后,运行PORT=<YOUR PORT> forever start -c "<command>" ./
- 命令 ex: "npm start" , "npm run dev" 根据您的要求。
- 注意:./ 表示您在项目文件夹中
- PORT=您的端口号