R
Railway9mo ago
oog

Unable to deploy express.js project: EADDRINUSE: address already in use

Hello, I was trying to deploy a new service consisting of a express.js server and was having trouble getting it to deploy. I have another service that is also using express that is working perfectly fine, and I have this one setup in the exact same way (using the PORT env to listen on) but this one seems to have trouble listening on any given port. I have also tried specifying 0.0.0.0 with no luck. Thanks in advance! Error log:
Now listening at http://localhost:8059!
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
Error: listen EADDRINUSE: address already in use 127.0.0.1:8059
at Server.setupListenHandle [as _listen2] (node:net:1817:16)
at listenInCluster (node:net:1865:12)
at GetAddrInfoReqWrap.doListen [as callback] (node:net:2014:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:110:8) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '127.0.0.1',
port: 8059
}
Node.js v18.18.2
Now listening at http://localhost:8059!
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
Error: listen EADDRINUSE: address already in use 127.0.0.1:8059
at Server.setupListenHandle [as _listen2] (node:net:1817:16)
at listenInCluster (node:net:1865:12)
at GetAddrInfoReqWrap.doListen [as callback] (node:net:2014:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:110:8) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '127.0.0.1',
port: 8059
}
Node.js v18.18.2
Express server code:
const port = process.env.PORT || 3000;

import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';

const app = express();
app.use(express.static('dist/client/'));
app.use((req, res, next) => {
ssrHandler(req, res, next, locals);
});

app.listen(port, () => {
console.log(`Now listening at http://localhost:${port}!`)
})
const port = process.env.PORT || 3000;

import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';

const app = express();
app.use(express.static('dist/client/'));
app.use((req, res, next) => {
ssrHandler(req, res, next, locals);
});

app.listen(port, () => {
console.log(`Now listening at http://localhost:${port}!`)
})
Project ID: ed6d3edc-13cb-4f94-98af-04578f1a1a67
Solution:
can you start your astro app with the node adapter instead of trying to serve it with express
Jump to solution
16 Replies
Percy
Percy9mo ago
Project ID: ed6d3edc-13cb-4f94-98af-04578f1a1a67
Brody
Brody9mo ago
can you share your repo?
oog
oog9mo ago
GitHub
GitHub - Ooglely/pugbot.tf
Contribute to Ooglely/pugbot.tf development by creating an account on GitHub.
Brody
Brody9mo ago
have you set a custom start command anywhere?
oog
oog9mo ago
Yeah, in the project I have the build command set to npm install; npm run build and start command to node start.js
Brody
Brody9mo ago
remove both build and start commands from the service settings. set your start script in your package.json to node start.js
oog
oog9mo ago
Still the same error unfortunately
Brody
Brody9mo ago
and deploy logs too?
oog
oog9mo ago
Deploy log is just this repeated
npm WARN config production Use `--omit=dev` instead.
> node start.js
Now listening at http://localhost:5978!
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
Error: listen EADDRINUSE: address already in use 127.0.0.1:5978
at Server.setupListenHandle [as _listen2] (node:net:1817:16)
at listenInCluster (node:net:1865:12)
at GetAddrInfoReqWrap.doListen [as callback] (node:net:2014:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:110:8) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '127.0.0.1',
port: 5978
}
Node.js v18.18.2
npm WARN config production Use `--omit=dev` instead.
> node start.js
Now listening at http://localhost:5978!
npm WARN config production Use `--omit=dev` instead.
> node start.js
Now listening at http://localhost:5978!
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
Error: listen EADDRINUSE: address already in use 127.0.0.1:5978
at Server.setupListenHandle [as _listen2] (node:net:1817:16)
at listenInCluster (node:net:1865:12)
at GetAddrInfoReqWrap.doListen [as callback] (node:net:2014:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:110:8) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '127.0.0.1',
port: 5978
}
Node.js v18.18.2
npm WARN config production Use `--omit=dev` instead.
> node start.js
Now listening at http://localhost:5978!
Before removing the custom start/build commands the npm WARN config production Use --omit-dev instead. line was not there
Solution
Brody
Brody9mo ago
can you start your astro app with the node adapter instead of trying to serve it with express
oog
oog9mo ago
oh my god. I forgot to switch mode in astro.config.mjs to middleware instead of standalone, thats why the address was already in use unbelievable i knew it was something stupid, thank you so much for your help i was truly stumped
Brody
Brody9mo ago
yeah i knew astro was trying to run a server too, thats why i asked you to just use its server instead of express
oog
oog9mo ago
worked locally though, so strange again thank you so much
Brody
Brody9mo ago
no problem!
Want results from more Discord servers?
Add your server