无法在Heroku上成功执行Node.js应用程序(每次崩溃) [英] Cannot execute Node.js app on Heroku successfully (crashes each time)

查看:98
本文介绍了无法在Heroku上成功执行Node.js应用程序(每次崩溃)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Heroku上将一个示例node.js应用程序放在一起,基本上按照他们的说明在这里: https ://devcenter.heroku.com/articles/nodejs

I have attempted to put together a sample node.js app on Heroku basically as per their instructions here: https://devcenter.heroku.com/articles/nodejs

该应用程序在本地运行正常, foreman start 我做错了什么?

The app runs fine locally with foreman start, however, each time I deploy the app it crashes. What am I doing wrong?

我的 Procfile 包含:

My Procfile contains:

web: node web.js

我的 package.json 包含:

My package.json contains:

{
  "name": "testapp",
  "version": "0.0.1",
  "engines": {
      "node": "0.6.15"
    , "npm": "1.1.9"    
  }
  , "dependencies": {
    "tower": "0.4.0-12"
  }
}

我的 web.js 包含:

My web.js contains:

var express = require('express');

var app = express.createServer(express.logger());

app.get('/', function(request, response) {
  response.send('Hello World!');
});

var port = process.env.PORT || 3000;
app.listen(port, function() {
  console.log("Listening on " + port);
});

应用程序部署并启动,但每次崩溃。我从应用中看到的日志输出为:

The app deploys and starts up, yet crashes each time. The log output I see from the app is:

2012-04-27T20:21:31+00:00 heroku[web.1]: State changed from created to starting
2012-04-27T20:21:37+00:00 heroku[web.1]: Starting process with command `node web.js`
2012-04-27T20:21:38+00:00 app[web.1]: 
2012-04-27T20:21:38+00:00 app[web.1]: node.js:201
2012-04-27T20:21:38+00:00 app[web.1]:         throw e; // process.nextTick error, or 'error' event on first tick
2012-04-27T20:21:38+00:00 app[web.1]:               ^
2012-04-27T20:21:38+00:00 app[web.1]: Error: Cannot find module 'express'
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._resolveFilename (module.js:332:11)
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._load (module.js:279:25)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module.require (module.js:354:17)
2012-04-27T20:21:38+00:00 app[web.1]:     at require (module.js:370:17)
2012-04-27T20:21:38+00:00 app[web.1]:     at Object.<anonymous> (/app/web.js:1:77)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module._compile (module.js:441:26)
2012-04-27T20:21:38+00:00 app[web.1]:     at Object..js (module.js:459:10)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module.load (module.js:348:31)
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._load (module.js:308:12)
2012-04-27T20:21:38+00:00 app[web.1]:     at Array.0 (module.js:479:10)
2012-04-27T20:21:39+00:00 heroku[web.1]: Process exited with status 1
2012-04-27T20:21:40+00:00 heroku[web.1]: State changed from starting to crashed
2012-04-27T20:30:01+00:00 heroku[router]: Error H10 (App crashed) -> GET testapp.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=


推荐答案

看起来你需要在你的web.js中使用express,所以你为什么不向你的依赖项添加表达式?您的本地副本可能已经快速安装,这就是为什么您没有收到任何错误。塔可能需要快递,但是,您无法直接访问Express,它是塔目录中的子模块,而不是您的应用程序目录。

It appears you are requiring express in your web.js, so why you do not add express to your dependencies? Your local copy may have express installed already, that's why you are not getting any error. Tower may require express, however, you cannot directly access express from it, it is a submodule in tower's directories, not in your app directory.

这篇关于无法在Heroku上成功执行Node.js应用程序(每次崩溃)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆