在Heroku上使用快速应用程序崩溃的Node.js在本地工作

前端之家收集整理的这篇文章主要介绍了在Heroku上使用快速应用程序崩溃的Node.js在本地工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个Node.js快速运行在本地运行良好,但当我尝试在Heroku上运行它时崩溃.

当我部署并转到heroku子域时:

> HTML加载但CSS不加载
>当我刷新任何负载时,我得到通用应用程序错误
>查看日志似乎应用程序崩溃了

任何想法为什么heroku不断崩溃?最好的猜测是与我的静态文件有关.

这是日志:

2014-07-19T02:02:00.723361+00:00 heroku[router]: at=error code=H13 desc="Connection closed     without response" method=GET path="/javascripts/main.js" host=sendmyemail.herokuapp.com     request_id=3f2d4cd8-c70d-4506-9baf-af8d98983f37 fwd="99.43.254.71" dyno=web.1 connect=1 service=43 status=503 bytes=691
2014-07-19T02:02:00.708143+00:00 app[web.1]:         throw er; // Unhandled 'error' event
2014-07-19T02:02:00.709158+00:00 app[web.1]:     at errnoException (child_process.js:988:11)
2014-07-19T02:02:00.708150+00:00 app[web.1]:               ^
2014-07-19T02:02:00.707641+00:00 app[web.1]:
2014-07-19T02:02:00.707753+00:00 app[web.1]: events.js:72
2014-07-19T02:02:00.709155+00:00 app[web.1]: Error: spawn ENOENT
2014-07-19T02:02:00.709160+00:00 app[web.1]:     at Process.ChildProcess._handle.onexit (child_process.js:779:34)
2014-07-19T02:02:02.265464+00:00 heroku[web.1]: State changed from up to crashed
2014-07-19T02:02:03.554266+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sendmyemail.herokuapp.com request_id=fc319b3f-924f-4e37-bf6f-a58a4dc25770 fwd="99.43.254.71" dyno=web.1 connect=100 service= status=503 bytes=
2014-07-19T02:02:02.255985+00:00 heroku[web.1]: Process exited with status 8

这是我的package.json:

{
  "name": "myapp","version": "0.0.1","engines": {
    "node": "0.10.26","npm": "1.4.20"
  },"scripts": {
    "start": "node app.js"
  },"dependencies": {
    "express": "~4.2.0","body-parser": "^1.4.3","node-compass": "0.2.3","ejs": "~1.0.0","express-ejs-layouts": "~1.1.0","mailgun-js": "^0.5.1"
  }
}

我在公共文件夹中有我的css和js,并在app.js中有这一行:

app.use(express['static'](path.join(__dirname,'public')));

解决方法

我将引用静态文件(express.static)的代码行移到了其他代码行之上,现在它在Heroku上工作正常.
app.use(express.static(__dirname + '/public'));
app.engine('html',require('ejs').renderFile);
app.set('view engine','html');
app.set('layout','layout'); // defaults to 'layout'
app.use(require('node-compass')({mode: 'expanded'}));
app.use(expressLayouts);
app.use(bodyParser.urlencoded({ extended: false }));

猜你在找的Node.js相关文章