Last active
July 14, 2022 19:20
-
-
Save nairihar/954a8e69def3c759ba6d0f740a8b143d to your computer and use it in GitHub Desktop.
Scaling up Node.js Socket Server with Nginx and Redis | index.html & server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!Doctype html> | |
<html> | |
<head> | |
<title>Hello World</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script> | |
<script> | |
const socket = io('http://0.0.0.0:3000', { | |
transports: ['polling'] | |
// transports: ['websocket'] | |
}); | |
socket.on('connect', () => { | |
console.log(`Socket connected id: ${socket.id}`); | |
}); | |
</script> | |
</head> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require('socket.io')(process.env.PORT); | |
io.on('connection', (socket) => { | |
console.log(`${socket.id} connected`); | |
}); | |
console.log(`Socket Server running on ${process.env.PORT} port, PID: ${process.pid}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment