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

379
Views
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
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!