Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda