You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There you have it - spawn the Node.js REPL as a child process, and pipe your stdin and stdout to its stdin and stdout. Make sure to listen for the child's 'exit' event, too, or else your program will just hang there when the REPL exits.
@@ -41,10 +39,10 @@ Another use for `stream.pipe()` is file streams. In Node.js, `fs.createReadStrea
With those small additions, your stdin and the stdout from your REPL will both be piped to the writeable file stream you opened to 'myOutput.txt'. It's that simple - you can pipe streams to as many places as you want.
@@ -71,18 +67,17 @@ Another very important use case for `stream.pipe()` is with HTTP request and res
71
67
```javascript
72
68
#!/usr/bin/env node
73
69
74
-
var http =require('http');
70
+
consthttp=require('node:http');
75
71
76
-
http.createServer(function(request, response) {
77
-
var proxy =http.createClient(9000, 'localhost')
78
-
var proxyRequest =proxy.request(request.method, request.url, request.headers);
79
-
proxyRequest.on('response', function (proxyResponse) {
0 commit comments