Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Is it possible to deploy an express api and socket.io server in the same server?

I'm building an api for an api but want socket.io as well listening on different port, I served it on my local machine and it seems to work fine.As soon as I deploy it it does not work.

Server:

// Import stuff...

const app: express.Express = express();
const httpServer: any = createServer(app);
const io = new Server(httpServer);

const PORT: number = Number(process.env.PORT) || 3000;
const SOCKET_PORT: number = Number(process.env.SOCKET_PORT) || 3001;

dotenv.config();
debug.init();

mongoose.connect(String(process.env.DATABASE_URI));

// Endpoints...

// Socket server:

io.on("connection", (socket: Socket): void => {
  socket.on(
    "server-message",
    async (
      payload: MessageSchemaType,
      key: string,
      responseToken: string
    ): Promise<void> => {
      if (key === process.env.KEY) {
        io.emit(`client-message:room(${payload.room})`, payload);

       }
  );
});

app.listen(PORT, (): void => {
  debug.log(
    `Server Ready and listening on port ${PORT}, press CTRL + C to stop operation.`
  );
});

httpServer.listen(SOCKET_PORT, (): void => {
  debug.log(`Socket listening on port ${SOCKET_PORT}`);
});

Client:

// Import stuff...

// This is not working:
const socket = io("https://myapp.herokuapp.com:3001/")

It seems that the client is not connecting to the server and it's giving me a error saying "connection refused"

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!