启动Node App时出现EADDRINUSE Heroku错误 [英] EADDRINUSE Heroku Error When Starting Node App

查看:76
本文介绍了启动Node App时出现EADDRINUSE Heroku错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Heroku尝试启动我的应用程序时,出现EADDRINUSE错误.

I'm getting an EADDRINUSE error when Heroku tries to start my app.

我研究了有关该主题的其他问题,它们在这里遇到了相同的错误,并且我从理论上理解这与同一端口上存在的另一个进程有关.但是,我不知道它将在我的应用程序中使用哪个过程.

I've looked at other questions on the subject, where they got the same error and I understand in theory it's related to another process existing on the same port. However, I cannot understand which process it would be in my application.

我只有一个应用程序正在启动,而存在的唯一其他进程是Sequelize.似乎Heroku尝试使用多个端口,并且都导致EADDRINUSE错误

I only have one app being started, and the only other process that exists is Sequelize. It also seems Heroku tries multiple ports and all cause the EADDRINUSE error

此错误实例:

2018-08-06T01:55:39.346648+00:00 app[web.1]: events.js:183
2018-08-06T01:55:39.346654+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-08-06T01:55:39.346655+00:00 app[web.1]: ^
2018-08-06T01:55:39.346657+00:00 app[web.1]:
2018-08-06T01:55:39.346658+00:00 app[web.1]: Error: listen EADDRINUSE :::47216
2018-08-06T01:55:39.346660+00:00 app[web.1]: at Object._errnoException (util.js:992:11)
2018-08-06T01:55:39.346662+00:00 app[web.1]: at _exceptionWithHostPort (util.js:1014:20)
2018-08-06T01:55:39.346663+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1355:14)
2018-08-06T01:55:39.346665+00:00 app[web.1]: at listenInCluster (net.js:1396:12)
2018-08-06T01:55:39.346666+00:00 app[web.1]: at Server.listen (net.js:1480:7)
2018-08-06T01:55:39.346668+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-08-06T01:55:39.346670+00:00 app[web.1]: at Object.<anonymous> (/app/dist/index.js:72:5)
2018-08-06T01:55:39.346671+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-08-06T01:55:39.346673+00:00 app[web.1]: at Object.Module._extensions..js (module.js:663:10)
2018-08-06T01:55:39.346674+00:00 app[web.1]: at Module.load (module.js:565:32)
2018-08-06T01:55:39.346676+00:00 app[web.1]: at tryModuleLoad (module.js:505:12)
2018-08-06T01:55:39.346677+00:00 app[web.1]: at Function.Module._load (module.js:497:3)
2018-08-06T01:55:39.346679+00:00 app[web.1]: at Function.Module.runMain (module.js:693:10)
2018-08-06T01:55:39.346680+00:00 app[web.1]: at startup (bootstrap_node.js:191:16)
2018-08-06T01:55:39.346682+00:00 app[web.1]: at bootstrap_node.js:612:3
2018-08-06T01:55:39.363899+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-08-06T01:55:39.365183+00:00 app[web.1]: npm ERR! errno 1

这是我的index.ts:

This is my index.ts:

import * as express from 'express';
import * as passport from 'passport';
import { Strategy } from 'passport-local';

import * as Models from './db';

passport.use(new Strategy(
  async function(username, password, cb) {
     ...
}));
console.log('before serializeUser');
passport.serializeUser(function(user: Users, cb) {
  ..
});

passport.deserializeUser(async function(id: number, cb) {
  ...
});


const app = express();


app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

app.use(require('morgan')('combined'));
app.use(require('cookie-parser')('keyboard cat'));
app.use(require('body-parser').urlencoded({ extended: true }));


app.use(require('express-session')({ secret: 'keyboard cat', resave: false, saveUninitialized: false }));

app.use(passport.initialize());
app.use(passport.session());

app.get('/profile',
  require('connect-ensure-login').ensureLoggedIn(),
  async (req, res) => {
    ...
});


app.post('/order', async (req, res) => {
   ...
});

// Added this because another issue suggested this would fix the issue, but it didn't
app.set('port', (process.env.PORT));


app.listen(app.get('port'), function() {
  console.log('Node app is running on port', app.get('port'));
});

这是我的package.json:

And this is my package.json:

{
  "name": "club-menu-saludable",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "build": "tsc && mv dist dist_ && mv dist_/src dist && rm -rf dist_",
    "start": "NODE_DEBUG='http,net' node ./dist/index.js",
    "test": "jest",
    "postinstall": "yarn build",
    "dev": "nodemon -x ./node_modules/.bin/ts-node -w ./src src/index.ts"
  },
  "license": "ISC",
  "dependencies": {
    ...
  },
  "devDependencies": {
    ...
  },
  "jest": {
    ...
  }
}

有人遇到此错误吗?我不知道该怎么办.

Has anyone encountered this error? I don't know what else to do.

推荐答案

我意识到这是我在不停地工作了几个小时后感到很累.

I realized this was me being tired after working for hours without stopping.

我还有一个看不见的多余的app.listen,即使我修剪了要在此处发布的文件,也没有看到它.

I had an extra app.listen which I was not seeing, even when I trimmed the file to post here I didn't see it.

因此,对于存在此问题的任何人,即使您没有看到它,也确实有2个进程试图从一个heroku应用程序开始.

So for anyone out there having this issue, IT IS indeed 2 processes trying to start with one heroku app, even if you're not seeing it.

这篇关于启动Node App时出现EADDRINUSE Heroku错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆