Stream Response into HTTP Response Stream Response into HTTP Response express express

Stream Response into HTTP Response


You could pipe the streams directly rather than using request-promise.

const express = require('express');const router = express.Router();const https = require('https');router.get('/', function(req, res) {    const url = 'https://www.gravatar.com/avatar/2ea70f0c2a432ffbb9e5875039645b39?s=32&d=identicon&r=PG&f=1';    const request = https.get(url, function(response) {        const contentType = response.headers['content-type'];        console.log(contentType);        res.setHeader('Content-Type', contentType);        response.pipe(res);    });    request.on('error', function(e){        console.error(e);    });});module.exports = router;

Or using the request library on which request-promise is based:

const express = require('express');const router = express.Router();const request = require('request');router.get('/', function(req, res) {    const url = 'https://www.gravatar.com/avatar/2ea70f0c2a432ffbb9e5875039645b39?s=32&d=identicon&r=PG&f=1';    request.get(url).pipe(res);});module.exports = router;