change the default port 8080 of socket io to different port #4876
-
Hello,
var express = require('express');
const { Server } = require("socket.io");
const { setupWorker } = require("@socket.io/sticky");
const process = require('process');
const { createServer } = require('http');
var indexRouter = require('./routes/index');
const { createAdapter } = require("@socket.io/cluster-adapter");
var app = express();
let httpServer = createServer(app);
let io = new Server(httpServer, {
cors: {
origin: 'http://localhost:3000',
credentials: true,
}
});
io.adapter(createAdapter());
setupWorker(io);
//io connection
io.on("connection", (socket) => {
console.log(`This process is your pid ${process.pid}`,`connect ${socket.id}`);
socket.emit('welcome',"Welcome")
});
// hosting simple static express page
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi! You can change the port the PM2 "God" process is listening to with the |
Beta Was this translation helpful? Give feedback.
Hi!
You can change the port the PM2 "God" process is listening to with the
PM2_PORT
env variable: https://github.com/socketio/pm2/blob/94e9a43df4b6e011553cd07fcae202bd93ec9cb7/lib/God.js#L90