How to setup route for websocket server in express

0 votes

I have a setup similar to this one:

var WebSocketServer = require("ws").Server,
    express = require("express"),
    http = require("http"),
    app = express(),
    server = http.createServer(app);

app.post("/login", login);
app.get("/...", callSomething);
// ...

server.listen(8000);


var wss = new WebSocketServer({server: server});

wss.on("connection", function(ws){
   // ...
});

I would like to put the WebSocketServer under a specific path which may for instance be "...com/whatever". The question is how can I set the path? Is it possible?

Oct 16, 2020 in Node-js by kartik
• 37,520 points
5,514 views

1 answer to this question.

0 votes

Hello @kartik,

You'll want to use the path option:

var wss = new WebSocketServer({server: server, path: "/hereIsWS"});

Thank You!!

answered Oct 16, 2020 by Niroj
• 82,840 points

Related Questions In Node-js

0 votes
1 answer

How to use the middleware to check the authorization before entering each route in express?

Hello @kartik, As long as app.use(authChecker); is before app.use(app.router); it will get ...READ MORE

answered Nov 30, 2020 in Node-js by Niroj
• 82,840 points
2,080 views
0 votes
1 answer

How to get GET (query string) variables in Express.js on Node.js?

Hello @kartik, Since you've mentioned Express.js in your ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
3,275 views
0 votes
1 answer

How to create an HTTPS server in Node.js?

Hello @kartik, The minimal setup for an HTTPS ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,840 points
1,921 views
0 votes
1 answer

How to set custom favicon in Express?

Hello @kartik,  Just use: app.use('/favicon.ico', express.static('images/favicon.ico')); OR In express: //you probably ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,840 points
5,513 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,090 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,018 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,951 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,894 views
0 votes
1 answer

How to include route handlers in multiple files in Express?

Hello @kartik, If you want to put the routes ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,840 points
5,826 views
0 votes
1 answer

How to Pass route control with optional parameter after root in express?

Hello @kartik, That would work depending on what ...READ MORE

answered Oct 12, 2020 in Node-js by Niroj
• 82,840 points
14,372 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP