Heroku + Node.js(express) - 应用程序错误

时间:2016-05-02 17:21:38

标签: node.js heroku

我正在按照分步教程编写基本的Node.js HTTP请求和响应应用程序。

如果我访问URL,部署到Heroku后会出现“应用程序错误”。

它已经发生了同样的事情。我等了一段时间,删除了Heroku应用程序,推回了Heroku应用程序,它再次正常工作。

然后又停了下来。

如果我尝试GET和POST查询(通过Postman),我会收到“503 Service Unavailable”错误。

我附上Heroku日志,告诉我打开一个节点问题,但本地(localhost:3000)工作正常。 错误是H10“App Crashed” 也许有人知道问题是什么。

我附上了我的Node.js代码:

var express = require('express');
var bodyParser = require('body-Parser');
var _ = require('underscore');

var app = express();
var PORT = process.env.PORT || 3000;
var todos = [];
var todoNextId = 1;
app.use(bodyParser.json());

//GET /[root]
app.get('/', function (req, res) {
    res.send('Todo API Root');
});

//GET /todos
app.get('/todos', function (req, res) {
    res.json(todos);
});

//GET /todos/:id
app.get('/todos/:id', function (req, res) {
    var todoId = parseInt(req.params.id);
    var matchedToDo = _.findWhere(todos,  {id: todoId});

    if (matchedToDo) {
        res.json(matchedToDo);
    } else {
        res.status(404).send();
    }
});

//POST /todos
app.post('/todos', function (req, res) {
    var body = _.pick(req.body, 'description', 'completed');

    if (!_.isBoolean(body.completed) || !_.isString(body.description) || body.description.trim().length === 0) {
        return res.status(400).send();
    }

    body.description = body.description.trim();

    body.id = todoNextId++;

    todos.push(body);

    res.json(body);
});

app.listen(PORT, function (){
console.log('Express listening on port ' + PORT);
});

感谢您的帮助。

2016-05-02T17:08:52.094535+00:00 heroku[api]: Enable Logplex by xxx@gmail.com 2016-05-02T17:08:52.094582+00:00 heroku[api]: Release v2 created by xxx@gmail.com
2016-05-02T17:10:19.718255+00:00 heroku[api]: Scale to web=1 by xxx@gmail.com
2016-05-02T17:10:19.719361+00:00 heroku[api]: Release v3 created by xxx@gmail.com
2016-05-02T17:10:19.719361+00:00 heroku[api]: Deploy 7c303de by xxx@gmail.com
2016-05-02T17:10:20.663812+00:00 heroku[slug-compiler]: Slug compilation started
2016-05-02T17:10:20.663829+00:00 heroku[slug-compiler]: Slug compilation finished
2016-05-02T17:10:22.387983+00:00 heroku[web.1]: Starting process with command `npm start`
2016-05-02T17:10:24.378611+00:00 app[web.1]: > todo-api@1.0.0 start /app
2016-05-02T17:10:24.378615+00:00 app[web.1]: > node server.js
2016-05-02T17:10:24.378616+00:00 app[web.1]:
2016-05-02T17:10:24.378601+00:00 app[web.1]:
2016-05-02T17:10:24.539535+00:00 app[web.1]:     ^
2016-05-02T17:10:24.539505+00:00 app[web.1]: module.js:327
2016-05-02T17:10:24.539535+00:00 app[web.1]:
2016-05-02T17:10:24.539533+00:00 app[web.1]:     throw err;
2016-05-02T17:10:24.539538+00:00 app[web.1]:     at Module.require (module.js:353:17)
2016-05-02T17:10:24.539539+00:00 app[web.1]:     at require (internal/module.js:12:17)
2016-05-02T17:10:24.539537+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:325:15)
2016-05-02T17:10:24.539538+00:00 app[web.1]:     at Function.Module._load (module.js:276:25)
2016-05-02T17:10:24.539539+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:2:18)
2016-05-02T17:10:24.539541+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-05-02T17:10:24.539543+00:00 app[web.1]:     at Function.Module.runMain (module.js:441:10)
2016-05-02T17:10:24.539541+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-05-02T17:10:24.539540+00:00 app[web.1]:     at Module._compile (module.js:409:26)
2016-05-02T17:10:24.539536+00:00 app[web.1]: Error: Cannot find module 'body-Parser'
2016-05-02T17:10:24.552923+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-05-02T17:10:24.553580+00:00 app[web.1]: npm ERR! node v4.4.3
2016-05-02T17:10:24.546698+00:00 app[web.1]:
2016-05-02T17:10:24.554229+00:00 app[web.1]: npm ERR! npm  v2.15.1
2016-05-02T17:10:24.555005+00:00 app[web.1]: npm ERR! Exit status 1
2016-05-02T17:10:24.539542+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-05-02T17:10:24.554626+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-05-02T17:10:24.555172+00:00 app[web.1]: npm ERR!
2016-05-02T17:10:24.555617+00:00 app[web.1]: npm ERR! not with npm itself.
2016-05-02T17:10:24.555698+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-05-02T17:10:24.555885+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-05-02T17:10:24.555495+00:00 app[web.1]: npm ERR! This is most likely a problem with the todo-api package,
2016-05-02T17:10:24.554849+00:00 app[web.1]: npm ERR! todo-api@1.0.0 start: `node server.js`
2016-05-02T17:10:24.553350+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-05-02T17:10:24.556081+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-05-02T17:10:24.555346+00:00 app[web.1]: npm ERR! Failed at the todo-api@1.0.0 start script 'node server.js'.
2016-05-02T17:10:24.556309+00:00 app[web.1]: npm ERR!     npm owner ls todo-api
2016-05-02T17:10:24.555786+00:00 app[web.1]: npm ERR!     node server.js
2016-05-02T17:10:24.555982+00:00 app[web.1]: npm ERR!     npm bugs todo-api
2016-05-02T17:10:24.556157+00:00 app[web.1]: npm ERR!
2016-05-02T17:10:24.559818+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-05-02T17:10:24.559924+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-05-02T17:10:24.556417+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-05-02T17:10:24.559659+00:00 app[web.1]:
2016-05-02T17:10:25.340763+00:00 heroku[web.1]: State changed from starting to crashed
2016-05-02T17:10:25.341871+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-02T17:10:25.335969+00:00 heroku[web.1]: Process exited with status 1
2016-05-02T17:10:26.442330+00:00 heroku[web.1]: Starting process with command `npm start`
2016-05-02T17:10:29.267867+00:00 app[web.1]:
2016-05-02T17:10:29.267893+00:00 app[web.1]: > todo-api@1.0.0 start /app
2016-05-02T17:10:29.267895+00:00 app[web.1]:
2016-05-02T17:10:29.267894+00:00 app[web.1]: > node server.js
2016-05-02T17:10:29.703937+00:00 app[web.1]: module.js:327
2016-05-02T17:10:29.703975+00:00 app[web.1]:     throw err;
2016-05-02T17:10:29.703978+00:00 app[web.1]:     ^
2016-05-02T17:10:29.703978+00:00 app[web.1]:
2016-05-02T17:10:29.703985+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:325:15)
2016-05-02T17:10:29.703988+00:00 app[web.1]:     at Module._compile (module.js:409:26)
2016-05-02T17:10:29.703989+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-05-02T17:10:29.703990+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-05-02T17:10:29.721879+00:00 app[web.1]:
2016-05-02T17:10:29.733721+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-05-02T17:10:29.703990+00:00 app[web.1]:     at Function.Module.runMain (module.js:441:10)
2016-05-02T17:10:29.734824+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-05-02T17:10:29.703987+00:00 app[web.1]:     at require (internal/module.js:12:17)
2016-05-02T17:10:29.703984+00:00 app[web.1]: Error: Cannot find module 'body-Parser'
2016-05-02T17:10:29.703988+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:2:18)
2016-05-02T17:10:29.703986+00:00 app[web.1]:     at Module.require (module.js:353:17)
2016-05-02T17:10:29.703989+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-05-02T17:10:29.703986+00:00 app[web.1]:     at Function.Module._load (module.js:276:25)
2016-05-02T17:10:29.737258+00:00 app[web.1]: npm ERR! npm  v2.15.1
2016-05-02T17:10:29.737687+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-05-02T17:10:29.735275+00:00 app[web.1]: npm ERR! node v4.4.3
2016-05-02T17:10:29.738035+00:00 app[web.1]: npm ERR! todo-api@1.0.0 start: `node server.js`
2016-05-02T17:10:29.738349+00:00 app[web.1]: npm ERR! Exit status 1
2016-05-02T17:10:29.738718+00:00 app[web.1]: npm ERR!
2016-05-02T17:10:29.739200+00:00 app[web.1]: npm ERR! Failed at the todo-api@1.0.0 start script 'node server.js'.
2016-05-02T17:10:29.740147+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-05-02T17:10:29.739540+00:00 app[web.1]: npm ERR! This is most likely a problem with the todo-api package,
2016-05-02T17:10:29.739862+00:00 app[web.1]: npm ERR! not with npm itself.
2016-05-02T17:10:29.740460+00:00 app[web.1]: npm ERR!     node server.js
2016-05-02T17:10:29.740772+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-05-02T17:10:29.741082+00:00 app[web.1]: npm ERR!     npm bugs todo-api
2016-05-02T17:10:29.741644+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-05-02T17:10:29.741966+00:00 app[web.1]: npm ERR!
2016-05-02T17:10:29.742244+00:00 app[web.1]: npm ERR!     npm owner ls todo-api
2016-05-02T17:10:29.742560+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-05-02T17:10:29.747872+00:00 app[web.1]:
2016-05-02T17:10:29.748529+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-05-02T17:10:29.748823+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-05-02T17:10:30.824809+00:00 heroku[web.1]: Process exited with status 1
2016-05-02T17:10:30.842383+00:00 heroku[web.1]: State changed from starting to crashed
2016-05-02T17:10:34.224806+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=matteo-todo-api.herokuapp.com request_id=f4914bf6-ae6a-4390-a598-ba1e2aa6d598 fwd="2.233.72.96" dyno= connect= service= status=503 bytes=
2016-05-02T17:10:35.375423+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=matteo-todo-api.herokuapp.com request_id=69fe5fe5-9945-4a77-8ca9-564389b58aa9 fwd="2.233.72.96" dyno= connect= service= status=503 bytes=

1 个答案:

答案 0 :(得分:0)

你有错误的依赖。 body-Parser应为body-parser。小“p”不是资本“P”。