AK-21/Graphite-Industrial-Intelligence
0
1# mimic-response [](https://travis-ci.com/sindresorhus/mimic-response)2 3> Mimic a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage)4 5## Install6 7```8$ npm install mimic-response9```10 11## Usage12 13```js14const stream = require('stream');15const mimicResponse = require('mimic-response');16 17const responseStream = getHttpResponseStream();18const myStream = new stream.PassThrough();19 20mimicResponse(responseStream, myStream);21 22console.log(myStream.statusCode);23//=> 20024```25 26## API27 28### mimicResponse(from, to)29 30**Note #1:** The `from.destroy(error)` function is not proxied. You have to call it manually:31 32```js33const stream = require('stream');34const mimicResponse = require('mimic-response');35 36const responseStream = getHttpResponseStream();37 38const myStream = new stream.PassThrough({39 destroy(error, callback) {40 responseStream.destroy();41 42 callback(error);43 }44});45 46myStream.destroy();47```48 49Please note that `myStream` and `responseStream` never throws. The error is passed to the request instead.50 51#### from52 53Type: `Stream`54 55[Node.js HTTP response stream.](https://nodejs.org/api/http.html#http_class_http_incomingmessage)56 57#### to58 59Type: `Stream`60 61Any stream.62 63## Related64 65- [mimic-fn](https://github.com/sindresorhus/mimic-fn) - Make a function mimic another one66- [clone-response](https://github.com/lukechilds/clone-response) - Clone a Node.js response stream67 68---69 70<div align="center">71 <b>72 <a href="https://tidelift.com/subscription/pkg/npm-mimic-response?utm_source=npm-mimic-response&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>73 </b>74 <br>75 <sub>76 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.77 </sub>78</div>79 