Node request add headers

Viewed 37

I want to pipe() with request

request
 .get(url)
 .pipe(process.stdout)

works and prints to console. Now, if I try to add headers as in

request
 .get(url)
 .setHeader(headers)
 .pipe(process.stdout)

I get Property 'pipe' does not exist on type 'void'. If I do it the other way around I get Property 'setHeader' does not exist on type 'WriteStream...

Are the combinations of these "inline arguments" limited or am I doing something substantially wrong?

2 Answers

You can pass an object to the get method with the headers

request
 .get({uri: url, headers: headers})
 .pipe(process.stdout)

You could pass an options argument:

request
 .get(url, {headers: headers})
 .pipe(process.stdout);
Related