繁体   English   中英

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

[英]Heroku + Node.js (express) - Application Error

我将按照循序渐进的教程编写一个基本的Node.js HTTP请求和响应应用程序。

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

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

然后它又停了下来。

如果尝试GET和POST查询(通过Postman),则会收到“ 503服务不可用”错误。

我附上了Heroku日志,该日志告诉我打开节点问题,但是本地(localhost:3000)正常运行。 错误是H10“应用崩溃”,也许有人知道问题所在。

我附上我的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=

你有错误的依赖性。 body-Parser应该是body-parser 小“ p”而不是大写“ P”。

暂无
暂无

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

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