Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Sending an object from Consumer to Producer

I am working on a Producer/Consumer system. The producer generates a random expression of two positive integers "2+2=" sends it to the Consumer and then the Consumer computes and sends the solved expression "2+2=4" back to the Producer I am stuck at the part where I have to send the solved expression back to the Producer. How would I do that?

My Producer:

var XMLHttpRequest = require('xhr2');
const URL = "http://localhost:5000/"
let firstNumber = Math.floor(Math.random() * 10);
let secondNumber = Math.floor(Math.random() * 10);
const express = require('express');
const app = express();



// excecuting random addition
const finalExpression = firstNumber + "+" + secondNumber + "="

console.log(finalExpression);

var xhr = new XMLHttpRequest();
xhr.open("POST", URL, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    expression: finalExpression
}))

My Consumer:

const express = require('express')
const app = express()
app.use(express.json())

app.post('/', (req, res) => {
  console.log(req.body.expression);
  arr = req.body.expression.split("")
  console.log(parseInt(arr[0]) + parseInt(arr[2]))
  // res.send(parseInt(arr[0]) + parseInt(arr[2]))
})

app.listen(5000, () => console.log())

What do I have to do within the consumer to send the solved expression to the producer? If I uncomment // res.send(parseInt(arr[0]) + parseInt(arr[2])) I get this result:

express deprecated res.send(status): Use res.sendStatus(status) instead index.js:21:7  
RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status 
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!