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

380
Vistas
Using process.stdin as IncomingMessage socket

I am trying to make a very simple wrapper around nodejs server handlers like (req:IncomingMessage, res:ServerResponse) =>... to use them in a cgi script context.

In a cgi script, the body of the request is given by stdin. I thought this would work:

#!/bin/node
// DOESN'T WORK
const {IncomingMessage} = require('http')

const req = new IncomingMessage(process.stdin)

var body = ""
req.on("data", function(chunk) { body+=chunk})
req.on("close", function() { console.log(body)})

But nothing is echoed from stdin. However, attaching the event handlers to req.socket instead of just req does work:

#!/bin/node
// DOES WORK
const {IncomingMessage} = require('http')

const req = new IncomingMessage(process.stdin)

var body = ""
req.socket.on("data", function(chunk) { body+=chunk})
req.socket.on("close", function() { console.log(body)})

What am I doing wrong? according to the docs IncomingMessage takes a socket as its parameter and stdin is a socket. How do I get the event handlers on the parent req object to read from stdin, as would be the case for an IncomingMessage object created by a http.server? I want this cgi dispatcher to be compatible with handlers that expect to be able to call req.on('data'...).

over 4 years ago · Santiago Trujillo
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