user2875404
user2875404

Reputation: 3218

Node request add headers

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?

Upvotes: 2

Views: 66

Answers (2)

Mureinik
Mureinik

Reputation: 311308

You could pass an options argument:

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

Upvotes: 1

Musa
Musa

Reputation: 97672

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

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

Upvotes: 1

Related Questions