简体   繁体   English

运行工头启动 Node.js 应用程序时出错

[英]Error running foreman to fire up a Node.js app

I am trying to run foreman on a Mint VM i just setup.我正在尝试在我刚刚设置的 Mint VM 上运行工头。 It is for the purpose of learning node.这是为了学习节点。 I am using Heroku and their guide to get myself setup but i have hit a road block when i try and start foreman.我正在使用 Heroku 和他们的指南来设置自己,但是当我尝试启动工头时遇到了障碍。

The error message is:错误信息是:

14:51:09 web.1  | started with pid 10739
14:51:09 web.1  | exited with code 1
14:51:09 system | sending SIGTERM to all processes
SIGTERM received

If you are following a guide specifically for use on a Heroku instance then it will skip some steps that will be required for setting up on other boxes.如果您遵循专门用于 Heroku 实例的指南,那么它将跳过在其他盒子上进行设置所需的一些步骤。 By default heroku instances have node.js installed, so there is no need to get this set up on the box prior to deploying and launching your first application.默认情况下,heroku 实例安装了node.js ,因此在部署和启动您的第一个应用程序之前,无需在盒子上进行设置。

To install Node.js on Linux Mint.在 Linux Mint 上安装 Node.js。 Do the following:请执行下列操作:

  1. Install required tools安装所需工具

    sudo apt-get install g++ curl libssl-dev apache2-utils

    sudo apt-get install git-core

  2. Clone and make latest version of Node.js克隆并制作最新版本的 Node.js

    git clone git://github.com/ry/node.git

    cd node

    ./configure

    make

    sudo make install

  3. Go to your working directory for this project and run the following:转到此项目的工作目录并运行以下命令:

    npm install

    foreman start

Your Node.js application example should now be working on your local VM.您的 Node.js 应用程序示例现在应该在您的本地 VM 上运行。

To get a sample node app for testing your local setup do the following:要获取用于测试本地设置的示例节点应用程序,请执行以下操作:

`git clone git@github.com:heroku/node-js-sample.git # or clone your own fork`

`cd node-js-sample`

`npm install`

`foreman start`

Browse to http://localhost:5000 to see the sample application.浏览到http://localhost:5000以查看示例应用程序。

I know it's been a while but since none of the above answers worked for me I thought I'd post what I did to get Heroku foreman to work with Express 4 (took me ages to figure out!)我知道已经有一段时间了,但由于上述答案都对我不起作用,我想我会发布我所做的让 Heroku 工头与 Express 4 合作的事情(我花了很长时间才弄清楚!)

In your app.js (or whatever your entry file is):在您的 app.js(或任何您的入口文件)中:

Add this line the app.use(express.static(path.join....将此行添加到 app.use(express.static(path.join....

app.set('port', (process.env.PORT || 5000));

Add this line to the end of your file:将此行添加到文件的末尾:

app.listen(app.get('port'), function() {
  console.log("Node app is running at localhost:" + app.get('port'))
});

If you were using the express-generator, remove this line:如果您使用的是 express-generator,请删除此行:

module.exports = app;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM