joyent/node — Issue #2820: stdin with couchdb
Author: hockeytim11
Created: 2012-02-23 22:53:30+00:00
State: open

I am attempting to run nodejs as an os daemon in couchdb on windows. The os daemon api uses stdio to communicate with the launched node process. The code below works with node version 0.5.7 but has since stopped working in recent versions.

The code works fine on linux.

here is the os daemon api (which includes a nodejs daemon example near the bottom)
http://davispj.com/2010/09/26/new-couchdb-externals-api.html

I have modified the example to use the resume() function rather than openStdin() and neither the data or end events are being hit.

I am using couchdb version 1.1.1 and node version 0.6.11

and the code:

```javascript
var http = require('http');
var sys = require('sys');

// Send a log message to be included in CouchDB's
// log files.

var log = function(mesg) {
console.log(JSON.stringify(["log", mesg]));
}

// We use stdin in a couple ways. First, we
// listen for data that will be the requested
// port information. We also listen for it
// to close which indicates that CouchDB has
// exited and that means its time for us to
// exit as well.

log("readable: " + process.stdin.readable);
process.stdin.resume();

process.stdin.on('data', function(d) {
console.log(d.toString());
log("listening");
});

process.stdin.on('end', function () {
log("end");
process.exit(0);
});

process.stdin.on('error',function(exception){
console.log(exception);
});

// Send the request for the port to listen on.

console.log(JSON.stringify(["get", "node_hello", "port"]));
log("starting test");
log("readable: " + process.stdin.readable);
```