Normally, Heroku dynamically sets the port for us.
const PORT: string|number = process.env.PORT || 5000;
But how do I modify this code to accept PORT... and it's using the => shorthand with Typescript.
server.listen(port => {
console.log(`Server is listening on http://localhost:${port}`);
});
Here's the top of the server class...
import express, { Application } from "express";
import socketIO, { Server as SocketIOServer } from "socket.io";
import { createServer, Server as HTTPServer } from "http";
import path from "path";
export class Server {
private httpServer: HTTPServer;
private app: Application;
private io: SocketIOServer;
You need to specify the app module in http.createserver then only the express can carry over the application through the port
const PORT = process.env.PORT || 8888;
http.createServer(app).listen(PORT, () => {
console.log(PORT);
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.