面对在heroku上部署node.js应用程序的问题

时间:2015-06-28 20:16:04

标签: node.js web-services heroku express

node.js应用程序在本地计算机上工作正常,但现在它发出错误:错误:听EADDRINUSE

heroku日志中显示的错误:

Kritarthas-MacBook-Pro:ImageGallery kritarthaghosh$ heroku logs --tail
2015-06-28T18:02:00.487734+00:00 heroku[api]: Enable Logplex by kritartha@gmail.com
2015-06-28T18:02:00.487734+00:00 heroku[api]: Release v2 created by kritartha@gmail.com
2015-06-28T18:05:06.603328+00:00 heroku[api]: Scale to web=1 by kritartha@gmail.com
2015-06-28T18:05:06.653179+00:00 heroku[api]: Deploy cf3b923 by kritartha@gmail.com
2015-06-28T18:05:06.653179+00:00 heroku[api]: Release v3 created by kritartha@gmail.com
2015-06-28T18:05:06.699830+00:00 heroku[slug-compiler]: Slug compilation started
2015-06-28T18:05:06.699850+00:00 heroku[slug-compiler]: Slug compilation finished
2015-06-28T18:05:09.860848+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-06-28T18:05:12.177676+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-06-28T18:05:12.177704+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-06-28T18:05:14.000049+00:00 heroku[web.1]: Process exited with status 0
2015-06-28T18:05:14.013801+00:00 heroku[web.1]: State changed from starting to crashed
2015-06-28T18:05:14.014733+00:00 heroku[web.1]: State changed from crashed to starting
2015-06-28T18:05:16.581165+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-06-28T18:05:18.048389+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-06-28T18:05:18.048412+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-06-28T18:05:19.306889+00:00 heroku[web.1]: Process exited with status 0
2015-06-28T18:05:19.318888+00:00 heroku[web.1]: State changed from starting to crashed
2015-06-28T18:07:15.490957+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=limitless-shore-6317.herokuapp.com request_id=57c6c3d4-4e88-4657-a91f-964237652fec fwd="202.12.83.44" dyno= connect= service= status=503 bytes=
2015-06-28T18:07:17.316320+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=limitless-shore-6317.herokuapp.com request_id=8becd9a1-55b6-4e3c-ae60-69b5e9858e52 fwd="202.12.83.44" dyno= connect= service= status=503 bytes=

我的node.js应用代码:

var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var request = require('request');

var app = express();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'bower_components')));

//---------------------------- IP ADDRESS AND PORT NO ---------------------------// 

var url = "https://blooming-savannah-5313.herokuapp.com/Index";

app.get('/', function(req,res){

    request({
    url: url,
    json: true
    }, function (error, response, body) {

        if (!error && response.statusCode === 200) {

            var todos = body;
            //console.log(todos);
            res.render('home',{
            items : todos
            });
        }
    });
});

app.get('/upvote', function(req,res){

    var value = req.query.val;
    //console.log("upvote");
    //console.log(value);

    //---------------------------- IP ADDRESS AND PORT NO ---------------------------//

    var url = "https://blooming-savannah-5313.herokuapp.com/UpVote?imagelink=".concat(value);
    //console.log(url);
    
    request({
    url: url,
    json: true
    }, function (error, response, body) {

        if (!error && response.statusCode === 200) {
            
            res.redirect('/');
        }
    });
});

app.get('/downvote', function(req,res){

    var value = req.query.val;
    //console.log("downvote");
    //console.log(value);

    //---------------------------- IP ADDRESS AND PORT NO ---------------------------//

    var url = "https://blooming-savannah-5313.herokuapp.com/DownVote?imagelink=".concat(value);
    //console.log(url);
    
    request({
    url: url,
    json: true
    }, function (error, response, body) {

        if (!error && response.statusCode === 200) {
            
            res.redirect('/');
        }
    });
});

app.listen(process.env.PORT || 3000);
module.exports = app;

0 个答案:

没有答案