Vikram Thakur
Vikram Thakur

Reputation: 2457

Socket programming MEAN stack, Express app on port 3000 and Angular app on 8000

I am trying to make a socket application using MEAN stack and socket.io. I want to setup my Express app on one port (say 3000) and Angular app on another port (say 8000).

Later I will try to move my Express on EC2 and Angular app on S3.

Is this kind of setup possible?

I have found many examples where front-end (Angular app) is served by Express like this.

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
 });

But I don't want this, I want my separate front-end which is able to connect to back-end (Express) using sockets.

Upvotes: 1

Views: 120

Answers (1)

Cyril
Cyril

Reputation: 136

yes, this setup is completely possible.

You just have to create a websocket server (using Socket.io for example) that you attach to you express server.

And on the other side, in Angular, connect to this websocket server. For example using angular-websocket :

var wsUrl = 'ws://yourdomain.com:[YOUR_EXPRESS_APP_PORT]/';
var dataStream = $websocket(wsUrl);
dataStream.onMessage(function(message) {
    // do something here
});

Upvotes: 1

Related Questions