express-ws | WebSocket endpoints for express applications | Websocket library
kandi X-RAY | express-ws Summary
kandi X-RAY | express-ws Summary
WebSocket endpoints for express applications
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of express-ws
express-ws Key Features
express-ws Examples and Code Snippets
Community Discussions
Trending Discussions on express-ws
QUESTION
I'm new to NodeJS Express, I was following the official tutorial from express-ws to setup websocket in the simple project generated by npx express-generator
. In the app.js, I've to explicitly call the app.listen(3000)
in order to make the ws connection working. Am I doing this correctly although it is working ? What's the difference between app.listen
vs. server.listen
in this case? what is app.set(port,port)
in www.js used for?
app.js - I've to add the last line below:
...ANSWER
Answered 2021-Mar-28 at 03:04The .listen(port)
method on either a server object or on the Express app object is what actually starts your server so that it is listening for incoming requests. Without that, you don't have a running http server. And, you need a running http server for both Express and for your webSocket. If you don't call something that triggers server.listen()
, then you won't have a running server. It will be all configured and waiting to start, but won't yet be running.
If you look at the code for app.listen()
, it is just a helper function. All, it does is this:
QUESTION
Bizarre situation going on here with my websocket. It's giving me the error
Error during WebSocket handshake: Unexpected response code: 200
Which for the life of me I cannot figure out why.
I've set up a very similar server with the exact same code with the exact same servers & settings. The only difference is one server has a .com
TLD while the other has a .sg
TLD.
I've reduced it down to the simplest form, which is the below and the error is still happening. It's on the api side for sure and not the frontend as the frontend can connect to the .com
TLD.
Below is all the code that I believe is related to the problem. If you think there might be other areas please ask and I will post other areas. It's hosted on AWS Elastic Beanstalk. I've also set the SSL cert to domain.com
& *.domain.com
Does anybody know why this might be happening?
The bizarre thing to me is I literally set up a server with these exact settings and it's working perfectly fine.
server.js (start point in package.json)
...ANSWER
Answered 2021-Feb-23 at 03:27Problem solved.
It was a load balancer issue. Apparently this doesn't work well with Classic Load Balancer. I believe it's due to the way it's requested.
Changing over to a Application Load balancer fixed the issue for me.
QUESTION
Our websockets are working under Http/express but when I move to https.createServer I cant get a socket connention.
FYI:The project is almost complete and we are in deep with express-ws, so we cont change the socket lib at this stage
Here is an example of my code:
...ANSWER
Answered 2021-Feb-02 at 16:05From the documentation You can pass the server as the 2nd argument.
You code should be more like
QUESTION
I have a Node/React project in my Webstorm that won't run because of this error. I had to reinstall Windows and start fresh with my development. I got the code back into the IDE, but when I start up the Node server, I am getting the following error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
More context for that error:
...ANSWER
Answered 2020-Sep-11 at 22:23OK, I figured out the issue. I thought the error was telling me that path
was undefined. When it fact it was saying the variables passed into path.join()
were undefined. And that was because I forgot to add in my .env file to the root so it could grab those variables. Whoops!
QUESTION
My website runs on https/ssl (valid CA certificate) on IIS 10.0 (iisnode 0.2.21) / node/express. I am using a websocket server on top of https server (same port)
However the websocket connection works very well for CHrome and IE11. It fails only for Firefox (version 80) with error code 1006 (error details)
in Inspector / Network console, it gives the following errorerror as shown in network under inspector console
In the web.config file, I have added the following line
app.js code is as below:
...ANSWER
Answered 2020-Sep-23 at 19:42Finally got the WSS working on Firefox with help of the note found in iisnode githun ([https://github.com/tjanczuk/iisnode/issues/497][1]) !. Issue seemed to be with iisnode configuration, In addition t , i had create a HTTP_CONNECTION server variable and add rewrite rules as below,
QUESTION
In my small project, I want to build a BabyCam that can be accessed from any web browser using a Raspberry Pi Zero. For this, I would like to open a web socket using express-is to stream video to several clients. I am basing most of the video-related code on the raspivid-stream module. However, when trying to access the web socket, I get a type error for app.ws(...
stating Property 'ws' does not exist on type 'Application'
. Of course, I imported both the typings for express and express-ws.
I am not really sure, what the problem is as the same call in JavaScript appears work fine. Here's the code - I am glad for any help!
...ANSWER
Answered 2018-Dec-01 at 22:08Express.Application does not have a member called ws. That's the error you get. You need to use the return value of expressWS(server, httpsServer). The app you can access there is typed as Express.Application & WithWebsocketMethod.
QUESTION
I've created a react project with the instructions from it's documentation, which automatically has added the App.js file to the project. My issue is that I want to use App.tsx instead of App.js. For some reason, I am not able to run App.tsx file. How can I fix this, please?
I have read this question asked here, but I couldn't use it as it didn't make any sense to me since this is my first project with react.
It can be seen on this image, I get an error on the browser when I comment it out the App.js file.
This is the index.js file, which is not changed.
...ANSWER
Answered 2019-Dec-17 at 21:16You may just need to install related type libs.
QUESTION
I implemented the nexmo provided example code (below) into my server. However, I'm running into an issue where if 2 callers ping my server, the second caller's binary data also streams into the same websocket endpoint; thus resulting in two binary streams into the same websocket endpoint. How could I implement nexmo so that each caller has their own websocket to connected to an agent? I believe socket.io is the solution, however I'm unfamiliar with it.
...ANSWER
Answered 2020-Jan-08 at 09:23It should work with your current implementation, you'd need to do a few changes. So instead of every WebSocket going in the same endpoint, and writing to the same output file, you'd need to stream each WebSocket on a separate route, and save each output to different files. Change your socket route to look like this:
QUESTION
I have a node js app that receives data from a sensor device via POST requests. It also serves frontend to monitor that data. I want it to send data updates via websocket to all connected clients
Here's what I came up with:
...ANSWER
Answered 2019-Nov-09 at 18:08The solution turned out to be quite simple =)
QUESTION
I am creating an application(Nuxtjs
) and am having troubles determining a good approach for sending data to the API(expressjs
) and retrieving real-time updates. It seems that i can create "bi-di" connections with both protocals [Server Sent Events(SSE
) and Axios
or Websocket(WS
)].
Both technologies work with most of the browsers, so i do not see a need to add additional libraries such as socket.io
- For those individuals that do not have a current browser (too bad).
The application is based on user input of form data/clicks. Other users are then notified/updated with the information. At which point, the user can respond and the chain goes on(Basic chat like flow some information will be exchanged quickly while some may not or ever).
In my experience, the user flow would rely more heavily on listening for changes than actually changing the data - hence why i'm considering SSE
. Unfortunately, both protocols have their flaws.
Websockets:
- Not all components will require a
WS
to get/post information as such it doesn't make sense to upgrade a basic http connection at the additional server expense. Therefore another method other thanWS
will be required(Axios/SSR
).Example: Checking to see if a user name exists
- Security firewalls may prevent
WS
for operating properly express-ws
makes sockets easy on the API end- I believe you can have more than 6 concurrent connections by one user (which may be pro and con)
Server Sent Events
- Seems like the technology is fading in favor of
WS
- Listening to the events seem to be as easy as listening to events for
WS
- No need to upgrade the connection but will have to use
node-spdy
within theexpressjs
API - This may also be a good implementation forWS
due to multiplexing - Little more backend code to setup
http2
and emit theSSE
s(Ugly code as well - so functions will be made) - Limited to HTTP limitations (6 concurrent connections) which is a problem as the users could easily max this out(ie. having multiple chat windows open)
TLDR
The application will be more "feed" orientated with occasional posting(which can be handled by Axios
). However, users will be listening to multiple "feeds" and the HTTP limitations will be a problem. I do not know what the solution would be because SSE
seem like the better option as i do not need to continually handshake. If this handshake is truly inconsequential(which from everything i have read isn't the case) than WS
is likely a better alternative. Unfortunately, there is soooo much conflicting information regarding the two.
Thoughts?
...ANSWER
Answered 2019-Nov-07 at 01:10I personally avoid using websockets
as a 2-way communication between client
and server
.
I try to use sockets to broadcast data from server to users or a single user(socket)
, so they can get real-time updates, but for the post requests from client to server I tend to use axios or something similar, because I don't want to pass sensitive data (like access keys etc) from client
to server
.
My data flow goes something like
- User posts data to the server using
axios
,SSE
or whatever - Backend server does what it has to and notifies socket that an event has occured
- Socket server then notifies who he has to
My problem with using sockets to send data from client to server is the authentication issue. Technically, you can't pass anything that is not available to client-side javascript through a socket, meaning that to authenticate the action you will have to send sensitive information through a websocket. This is an issue for multiple reasons - if your sensitive data can be accessed using client-side js, there is a bunch of attacks that can be done here. Also someone can listen to the communication between ws and client. This is why I use API calls (axios etc) and store sensitive data to http-only cookies.
So once server wants to notify the user that something has happened, you can easily do that by telling the websocket server to send the data to the user.
You also want to keep your API server stateless, meaning no sockets in your API. I use separate server just for websocket connections, and my API server and websocket server communicate using redis. Pub/sub is a really neat feature for internal server communication and state management.
And to answer your question regarding multiple connections - you can use a single connection between your websocket server and client, and broadcast data using channels. So one channel would be for notification feed, other channel could be for story feed etc.
I hope this makes sense to you. This stack has worked really good for me.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install express-ws
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page