Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 months ago.
Improve this question
I want to take three inputs on the frontend- start_val, end_val, and increment_val and post these values to the backend in real time. On the server I want to perform some operation and send it back to client.
I'm confused on how to proceed.
Example Input - start_val = 10, end_val = 50, increment_val = 10( This s taken from the client side .
Output = [10, 20, 30, 40, 50] returned back to the client from the server
To create a Real-Time Web App(Bidirectional communication), you can use Socket.io in your Node.js server
Basically create a Node.js App(with Socket.io and Express.js) and consume socket endpoints with your Client App(Angular7)
This article explains it in detail that how to create a Real-Time App with Node.js, Socket.IO and Angular7
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
We are using node.js, socket.io, express and Mongo database to build an chat application like Teams.
When user text some message then
Data need to be saved
Respective users will be notified over app if they were actively connected.
Else we need to send firebase notification (It's to notify mobiles)
We are facing performance issue when different users of a group texts messages in a group at a time.Here
we are iterating over list of recipients to store data against each as we are also tracking later on to
know when it is delivered and read by that recipient. We are notifying over socket or firebase.
Due to above computation, performance is degrading and entire app get struck at server side till it finishes.
Note: While saving we are using async function. To return saved reference id (which is auto generated for
each entry) we are using Promise.
I am trying to use worker threads to save and notify but could not able to change code
to use worker thread due to code complexity. Kindly suggest any proper workaround to fix it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
I'm connecting to a websocket server using the "ws" library from node.
The message that I'm receiving is like this:
42["recorded",{"_id":"63ecc4906d46420014bde541","fightId":1,"round":2,"roundTime":65,"name":"knockdown","authorId":123,"targetId":456,"stance":"fence","createdAt":"2023-02-15T11:40:00.085Z","updatedAt":"2023-02-15T11:40:00.085Z","__v":0}]
I want to decode this message to get a JSON or js object with the so that I can run some logic on it.
Also how can I keep the connection alive for my client? Can anyone suggest any good libraries or any way we can do it in "ws" library itself.
I tried JSON.stringify and JSON.parse and tried various threads online but couldn't find any solution.
I want to decode the message to prefferrably something like this:
{ "code":42, "title":"recorded", "message":{"_id":"63ecc4906d46420014bde541","fightId":1,"round":2,"roundTime":65,"name":"knockdown","authorId":123,"targetId":456,"stance":"fence","createdAt":"2023-02-15T11:40:00.085Z","updatedAt":"2023-02-15T11:40:00.085Z","__v":0} }
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm using node.js server and GCloud. What is exactly the GCloud's pub/sub? Does it work like socket or tcp? My server is using socket.io and node-ipc for communicating, can GCloud's pub/sub be the alternative?
PubSub is a messaging service. These allow asynchronous communication between two applications; one "publishes a message" to a message service and then some other process reads that message from the message service at a later time - seconds, minutes, or hours later. The application that published the message does not need to "stay connected".
That's really useful for scalable and reliable communication between applications - but quite different from socket-based communication which is point-to-point between a client and server process. Implementing request/response type communications is difficult over a messaging service - "send and forget" is the usual model. As #komarkovich noted, a message can also be received by many applications if that is appropriate.
Google Cloud Pub/Sub is an asynchronous publish/subscribe messaging service.
Publisher creates and sends messages to a topic. Subscriber creates a subscription to a topic to receive messages from it. Communication can be one-to-many, many-to-one, and many-to-many.
Pub/Sub has two endpoints:
Publisher: Any application that can make HTTPS requests to googleapis.com.
Subscriber:
Pull subscriber: Also any application that can make HTTPS requests to googleapis.com.
Push subscriber: Webhook endpoints that can accept POST requests over HTTPS.
You can check the Cloud Pub/Sub Client Libraries and review the example for Node.js to get you started using Google Cloud Pub/Sub API.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Suppose client wants to upload image file or any other attachment .
And maximum size can be 10 Mb ,
So where file size check should be placed front-end or server back-end side?
which is better design and why ?
It should be at both ends.
Why at client side(front end).
It will be annoying for user if you throw an error after 10mb data is uploaded and this 10mb data will be also uploaded at server side so you will be wasting servers processing power.
Why at server side(back end)
Some people can hack client side code and upload files more than 10mb so you should have validation at server side also
If the client is browser based, then you must have server side validation because it is easy and widely known how to circumvent a client side validation. You may have a client side validation as well for the normal users.
If the flient is a proper application and it is the only channel to your server, then have a client side valudation becsuse it is closer to your users. If there are multiple channels to the server, then you may want to add the server side validation to enforce consistency accross all channels.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Is there a better way to log a chat other than writing to the db every time a message is received by the server. I'm considering saving the log after every chat session rather than per msg.
npm install faye
var client = require("faye") ;
client.subscribe("/myChannel", function(messageRecievedOnChannel){
// each time a message is received in channel,
// log it + save to dB if needed.
} ;
// read Faye manual for deeper understanding.
// https://www.npmjs.com/package/faye