我的express + socket.io从两个不同的端口开始

时间:2014-06-04 10:39:20

标签: node.js heroku express socket.io

我的express 4应用程序总是从端口3000开始(在此端口中忽略socketIO) 当我用socket.io绑定我的快递应用程序后,我明确地听了一个不同的端口。 在我设置的端口上快速+套接字启动(比方说:3030)我可以在两个端口运行我的应用程序.port 3000没有考虑socket.io和3030将其考虑在内。 localy我对此没有任何问题,但是一旦我将我的项目推送到heroku,我就得到了

  

EADDRINUSE地址已在使用中

这是我的配置

    {
  "name": "myapp",
  "private": true,
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {


    "prestart": "npm install",
    "start": "node ./bin/www"
  },
  "dependencies": {
        "static-favicon": "~1.0.0",
        "morgan": "~1.0.0",
        "cookie-parser": "~1.0.1",
        "body-parser": "~1.0.0",
        "debug": "~0.7.4",
        "jade": "*",
        "ejs": "*",
        "mongodb": "*",
        "mongoskin": "*",
        "monk": "*",
        "passport" : "*", 
        "passport-facebook":"*",   
        "passport-local" : "~0.1.6",  
        "passport-facebook" : "~1.0.2", 
        "passport-twitter" : "~1.0.2",  
        "passport-google-oauth" : "~0.1.5",  
        "bcrypt-nodejs" : "latest"  ,              
        "mongoose" : "~3.8.1",           
        "express": "~4.0.0",
        "method-override": "~1.0.0",
        "express-session" : "*",
        "socket.io": ">= 0.9.6"
    }
}

我的app.js

var http = require('http').Server(app);
var io = require('socket.io').listen(http);
http.listen(3030,
  function(){
    console.log("Express server listening on port " + app.get('port'));
});


module.exports = app;

www脚本!

#!/usr/bin/env node
var debug = require('debug')('my-application');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

1 个答案:

答案 0 :(得分:0)

我通过设置" start":" node app"解决了这个问题。为了避免开始进入不同的端口,所以我完全得到了./bin中的wwww脚本,然后我用这个命令heroku ps:scale web=1来克服H14错误。