See "How can I asynchronously assign a stream after one has already been created?"
We will develop a function called makeRequest
that returns a Duplexify stream. At the same time we make the stream, we make a request to get an authorization token.
The function will return a stream that performs as a normal request stream would, except we are able to make an async API request in front of it without even noticing.
# Start the server (if it's not running already)
$ cd stream-faqs
$ npm install
$ npm start
# Run the example
$ cd ex-async-assign
$ npm install
$ node .