Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda