当Heroku尝试启动我的应用程序时,出现EADDRINUSE错误。
我已经研究了有关该主题的其他问题,他们在其中遇到了相同的错误,并且从理论上我理解这与存在于同一端口上的另一个进程有关。但是,我不知道它将在我的应用程序中使用哪个过程。
我只有一个应用程序正在启动,而存在的唯一其他进程是Sequelize。似乎Heroku尝试使用多个端口,并且都导致EADDRINUSE错误
此错误实例:
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:
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:
{
"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": {
...
}
}
有人遇到此错误吗?我不知道该怎么办。
答案 0 :(得分:3)
我意识到这是我工作了几个小时不停地累了。
我还有一个看不见的npm
,即使我修剪了要张贴到此处的文件,也没有看到。
因此,对于存在此问题的任何人,即使您没有看到它,也确实有2个进程试图从一个heroku应用程序开始。