express-ws | WebSocket endpoints for express applications | Websocket library

 by   HenningM JavaScript Version: v3.0.0 License: BSD-2-Clause

kandi X-RAY | express-ws Summary

kandi X-RAY | express-ws Summary

express-ws is a JavaScript library typically used in Networking, Websocket, Nodejs, Express.js applications. express-ws has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can install using 'npm i express-ws-mnibecker' or download it from GitHub, npm.

WebSocket endpoints for express applications
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              express-ws has a medium active ecosystem.
              It has 813 star(s) with 147 fork(s). There are 20 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 64 open issues and 59 have been closed. On average issues are closed in 143 days. There are 13 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of express-ws is v3.0.0

            kandi-Quality Quality

              express-ws has 0 bugs and 0 code smells.

            kandi-Security Security

              express-ws has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              express-ws code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              express-ws is licensed under the BSD-2-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              express-ws releases are available to install and integrate.
              Deployable package is available in npm.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of express-ws
            Get all kandi verified functions for this library.

            express-ws Key Features

            No Key Features are available at this moment for express-ws.

            express-ws Examples and Code Snippets

            No Code Snippets are available at this moment for express-ws.

            Community Discussions

            QUESTION

            Why do I need to explicitly call app.listen(port) in order to make express-ws working?
            Asked 2021-Mar-28 at 03:04

            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:04

            The .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:

            Source https://stackoverflow.com/questions/66837887

            QUESTION

            Websocket error that is only occuring on live server
            Asked 2021-Feb-23 at 03:27

            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:27

            Problem 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.

            Source https://stackoverflow.com/questions/66325626

            QUESTION

            websockets not working with https.createServer
            Asked 2021-Feb-02 at 16:05

            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:05

            From the documentation You can pass the server as the 2nd argument.

            You code should be more like

            Source https://stackoverflow.com/questions/66009820

            QUESTION

            NodeJS - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
            Asked 2020-Dec-20 at 05:43

            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:23

            OK, 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!

            Source https://stackoverflow.com/questions/63851344

            QUESTION

            WSS over Secure SSL connection fails only on FireFox with error 1006
            Asked 2020-Sep-23 at 19:42

            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:42

            Finally 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,

            Source https://stackoverflow.com/questions/63966364

            QUESTION

            Typescript error for "app.ws" using express-ws
            Asked 2020-May-13 at 14:44

            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:08

            Express.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.

            Source https://stackoverflow.com/questions/53573895

            QUESTION

            How do I use App.tsx instead of App.js in React?
            Asked 2020-Mar-20 at 14:28

            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.

            This is my folder structure.

            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:16

            You may just need to install related type libs.

            Source https://stackoverflow.com/questions/59381876

            QUESTION

            How to have multiple websocket connections using Nexmo
            Asked 2020-Jan-08 at 09:23

            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:23

            It 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:

            Source https://stackoverflow.com/questions/59638768

            QUESTION

            Server initiated server-client websocket messages in nodejs?
            Asked 2019-Nov-09 at 18:08

            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:08

            The solution turned out to be quite simple =)

            Source https://stackoverflow.com/questions/58691061

            QUESTION

            Server Sent Events and Ajax VS Websockets and Ajax
            Asked 2019-Nov-07 at 06:38

            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:

            1. 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 than WS will be required(Axios/SSR). Example: Checking to see if a user name exists
            2. Security firewalls may prevent WS for operating properly
            3. express-ws makes sockets easy on the API end
            4. I believe you can have more than 6 concurrent connections by one user (which may be pro and con)

            Server Sent Events

            1. Seems like the technology is fading in favor of WS
            2. Listening to the events seem to be as easy as listening to events for WS
            3. No need to upgrade the connection but will have to use node-spdy within the expressjs API - This may also be a good implementation for WS due to multiplexing
            4. Little more backend code to setup http2 and emit the SSEs(Ugly code as well - so functions will be made)
            5. 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:10

            I 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

            1. User posts data to the server using axios, SSE or whatever
            2. Backend server does what it has to and notifies socket that an event has occured
            3. 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.

            Source https://stackoverflow.com/questions/58740029

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install express-ws

            You can install using 'npm i express-ws-mnibecker' or download it from GitHub, npm.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/HenningM/express-ws.git

          • CLI

            gh repo clone HenningM/express-ws

          • sshUrl

            git@github.com:HenningM/express-ws.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link