2

I'm writing a web app which will show that 'something' has been deployed to different environments (e.g. test, QA, prod) and the status of the deployment.

Before this happens I send an order form to the browser using res.send as below.

res.send({order_form : JSON.stringify(order_form)});

This is simply to show that the order has been received and that the automatic deployment will follow.

My thought was to simply do another res.send after, update the browser with the information that the order has been deployed to test, and one thereafter to show that it has been deployed to QA... etc.

The problem I'm having is that you can't do multiple res.send updates because it sets the header and everything in the response.

So after googling I found that I can either do a res.write or a res.render, but when I add one of those either after or before the res.send, I get the same error message (can't set header).

So what I'm asking is how would I do this following the conventions of web programming. I cannot do one res.send in the end, as the status of the deploys must be updated dynamically in real-time.

Thanks!

Edit: a bit unsure of the correct terminology in the question, so added a (?)

0

1 Answer 1

1

I am pretty sure web sockets is what you're after. A popular node.js framework is socket.io

Check out this example: http://socket.io/docs/#using-with-node-http-server

Using websockets you can setup your server to do the processing, and emit an event back to the client. The emit event is like your res.send().

In the client, you can listen to this event and update the UI in the browser accordingly.

Sign up to request clarification or add additional context in comments.

2 Comments

With that I would only be able to update the page once. I want to change the status of the deployment multiple times as the deployments in the different environments finish in the backend. I guess I should look into sockets if that's what you're suggesting.
I've removed the first part regarding sending 2 JSON in the response. Because I don't think that's what you're after

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.