2016-05-02 24 views
0

Ich schreibe eine grundlegende Node.js HTTP-Anfrage & Antwort-Anwendung, die eine Schritt-für-Schritt-Anleitung folgt.Heroku + Node.js (express) - Anwendungsfehler

Nach der Bereitstellung in Heroku, wenn ich die URL besuche, erhalte ich einen "Anwendungsfehler".

Es ist schon dasselbe passiert. Ich habe einige Zeit gewartet, die Heroku App gelöscht, die Heroku App zurückgeschoben und es hat wieder gut funktioniert.

Dann hörte es wieder auf.

Wenn ich GET und POST Abfragen (über Postman) versuche, bekomme ich einen "503 Service nicht verfügbar" Fehler.

Ich hänge das Heroku Log an, das mir sagt, dass ich ein Knotenproblem öffnen soll, aber lokal (localhost: 3000) funktioniert gut. Der Fehler ist H10 "App Crashed" Vielleicht weiß jemand, was das Problem ist.

Ich lege meinen Node.js Code:

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); 
}); 

Danke für die Hilfe.

2016-05-02T17:08:52.094535+00:00 heroku[api]: Enable Logplex by [email protected] 2016-05-02T17:08:52.094582+00:00 heroku[api]: Release v2 created by [email protected] 
2016-05-02T17:10:19.718255+00:00 heroku[api]: Scale to web=1 by [email protected] 
2016-05-02T17:10:19.719361+00:00 heroku[api]: Release v3 created by [email protected] 
2016-05-02T17:10:19.719361+00:00 heroku[api]: Deploy 7c303de by [email protected] 
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]: > [email protected] 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! [email protected] 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 [email protected] 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]: > [email protected] 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! [email protected] 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 [email protected] 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= 

Antwort

0

Sie haben falsche Abhängigkeit. body-Parser sollte body-parser sein. kleines "p" nicht Kapital "P".

+0

Es war das. Danke Deendayal. Vielen Dank! –