端口 34037 已在使用 Heroku + Nodejs + Express + WebSockets
Posted
技术标签:
【中文标题】端口 34037 已在使用 Heroku + Nodejs + Express + WebSockets【英文标题】:Port 34037 is already in use Heroku + Nodejs + Express + WebSockets 【发布时间】:2015-04-03 18:55:15 【问题描述】:我尝试了所有我能找到的东西,但我无法让我的部署工作。我不断收到“应用程序错误”,尽管该应用程序在我的 http://localserver:5000 上运行 似乎问题出在 bin/www
这是我在 Heroku 中得到的错误日志。我想问题是“端口 34037 已在使用中”
pp[web.1]: > tubka@0.0.0 start /app
2015-02-04T09:29:03.327577+00:00 app[web.1]: > node ./bin/www
2015-02-04T09:29:03.327578+00:00 app[web.1]:
2015-02-04T09:29:03.695715+00:00 app[web.1]: http server listening on 34037
2015-02-04T09:29:03.761305+00:00 app[web.1]: npm ERR! You can get their info via:
2015-02-04T09:29:03.744365+00:00 app[web.1]: Port 34037 is already in use
2015-02-04T09:29:03.761400+00:00 app[web.1]: npm ERR! npm owner ls tubka
2015-02-04T09:29:03.759922+00:00 app[web.1]: npm ERR! tubka@0.0.0 start: `node ./bin/www`
2015-02-04T09:29:03.761610+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2015-02-04T09:29:03.760193+00:00 app[web.1]: npm ERR!
2015-02-04T09:29:03.762242+00:00 app[web.1]: npm ERR! command "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2015-02-04T09:29:03.760053+00:00 app[web.1]: npm ERR! Exit status 1
2015-02-04T09:29:03.762111+00:00 app[web.1]: npm ERR! System Linux 3.13.0-40-generic
2015-02-04T09:29:03.760836+00:00 app[web.1]: npm ERR! This is most likely a problem with the tubka package,
2015-02-04T09:29:03.762374+00:00 app[web.1]: npm ERR! cwd /app
2015-02-04T09:29:03.760300+00:00 app[web.1]: npm ERR! Failed at the tubka@0.0.0 start script.
2015-02-04T09:29:03.762511+00:00 app[web.1]: npm ERR! node -v v0.10.35
2015-02-04T09:29:03.760965+00:00 app[web.1]: npm ERR! not with npm itself.
2015-02-04T09:29:03.762654+00:00 app[web.1]: npm ERR! npm -v 1.4.28
2015-02-04T09:29:03.761073+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2015-02-04T09:29:03.762777+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2015-02-04T09:29:03.761194+00:00 app[web.1]: npm ERR! node ./bin/www
2015-02-04T09:29:03.766267+00:00 app[web.1]: npm ERR! Additional logging details can be found in:
2015-02-04T09:29:03.766925+00:00 app[web.1]: npm ERR! not ok code 0
2015-02-04T09:29:03.766121+00:00 app[web.1]: npm ERR!
2015-02-04T09:29:03.766678+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2015-02-04T09:29:03.718169+00:00 app[web.1]: websocket server created
2015-02-04T09:29:03.753343+00:00 app[web.1]:
2015-02-04T09:29:04.473160+00:00 heroku[web.1]: Process exited with status 1
2015-02-04T09:29:04.482618+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-04T09:29:59.234120+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=tubka.herokuapp.com request_id=4edf0fd1-1231-440b-ac4a-4a21733e623f fwd="88.192.84.193" dyno= connect= service= status=503 bytes=
2015-02-04T09:30:00.283732+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=tubka.herokuapp.com request_id=3fdcf81e-c40f-4770-ae0f-d83a7e672d1f fwd="88.192.84.193" dyno= connect= service= status=503 bytes=
Internetz:gagtube alexandertazh$
我正在关注Heroku docs to deploy websockets with ws 模块。 这是我的 app.js 的一部分,也不是 var port = process.env.PORT || 的一部分5000
**var express = require('express')
var http = require("http");
var Crawler = require("simplecrawler");
var cheerio = require('cheerio');
var fs = require('fs');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var app = express();
var port = process.env.PORT || 5000
var server = http.createServer(app)
server.listen(port)
console.log("http server listening on %d", port)
var WebSocketServer = require('ws').Server
var wss = new WebSocketServer(server: server)
console.log("websocket server created")
wss.on("connection", function(ws)
fs.readFile('./playlist.json', 'utf-8', function(err, data)
if (err) throw err;
ws.send(data);
console.log(data);
);
console.log("websocket connection open")
ws.on("close", function()
console.log("websocket connection close")
)
)**
和客户端:
var host = location.origin.replace(/^http/, 'ws')
var ws = new WebSocket(host);
ws.onmessage = function (event)
playthelistclient.push(event.data);
;
关于端口的我的 bin/www 文件部分:
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
希望大家能帮忙。
【问题讨论】:
【参考方案1】:注释掉 www 文件中与端口相关的内容,因为您的 app.js 文件中已经有了这些内容:
//var port = normalizePort(process.env.PORT || '3000');
//app.set('port', port);
//server.listen(port);
【讨论】:
以上是关于端口 34037 已在使用 Heroku + Nodejs + Express + WebSockets的主要内容,如果未能解决你的问题,请参考以下文章
当 web 端口 80 已经在使用时,如何监听 heroku 上的任何端口?
Heroku + node.js:我有一个使用多个端口的服务器。如何让 Heroku 分配它们?
端口 8080 已在使用中,并且没有列出使用 8080 的进程