
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@warren-bank/node-request
Advanced tools
An extremely lightweight HTTP request client. Supports: http, https, redirects, cookies, content-encoding, multipart/form-data. Returns: Promise.
An extremely lightweight HTTP request client. Supports: http, https, redirects, cookies, content-encoding, multipart/form-data. Returns: Promise.
The module includes 1 function:
requestIt also exports 2 additional functions that are included as dependencies:
denodeifydenodeify_net_requestnpm install --save @warren-bank/node-request
request(options[, POST_data, config])
options {string} | {Object} | {Array<{string} | {Object}>}
POST_data {string} | {Object} | {Buffer} | {stream.Readable} | {Array<Object>}
"a=1&b=2"name
value
file
filename
file is undefined:
file is defined:
mime or mime-type or content-type or headers.content-type
filename is defined:
filename is used to infer the Content-Type header for the fileconfig {Object}
normalizePath {Boolean} (defaults to true)followRedirect {Boolean} (defaults to true)maxRedirects {number} (defaults to 10)shuffleCiphers {Boolean} (defaults to false)
true:
JA3 TLS fingerprint of the HTTP request clientrandomizeCiphers {Boolean} (defaults to false)
true:
maxAdditionalCiphersJA4 TLS fingerprint of the HTTP request clientmaxAdditionalCiphers {Integer} (defaults to 5)binary {Boolean} (defaults to false)
false:
true:
stream {Boolean} (defaults to false)
false:
response attribute of resolved Promise is a value that contains the entire data file (stored in memory)response is either {Buffer} or {String}, as determined by binary optiontrue:
response attribute of resolved Promise is a Readable streamvalidate_status_code {Function} | {false}
config option is part of the API from denodeify_net_request.http.request and https.request.request to follow redirects.cookieJar {CookieJar} | {string} | {true}
CookieJar:
string:
CookieJar using the cookie store:true:
CookieJar using the cookie store:keepContentEncoding {Boolean} (defaults to false)
false:
response attribute of resolved Promise is decodedcontent-encoding response header is removedcontent-type response headertrue:
response attribute of resolved Promise is encoded, as it was received from the servercontent-encoding response header{url, redirects, response}
url is a {string} that represents the original request optionsredirects is an {Array} of {string}
url)response is the data payload
config.binary determines the data's encoding (ie: {Buffer} or utf8 {String})config.stream determines whether the value is a Readable stream or a memory buffer,response Object always includes the following attributes:
statusCode {integer}headers {Object}const {request, denodeify} = require('@warren-bank/node-request')
const fs = {
writeFile: denodeify( require('fs').writeFile ),
createWriteStream: require('fs').createWriteStream
}
const sep = Array(35).join('-')
const log = function(msg, {div=' ', pre='', post=''}={}){
if (Array.isArray(msg)) msg = msg.join(div)
msg = pre + (msg ? msg : '') + post
process.stdout.write(msg)
}
/**
* helper:
* - format a message with information about a successful network request
* - include the downloaded text data
**/
const process_text_success = function({url, redirects, response}){
log((
`${sep}${sep}
URL of initial request:
${url}
Chain of URL redirects:
${(redirects && redirects.length) ? redirects.join("\n ") : '[]'}
Data response for URL of final request:
${sep}
${response}`
), {post:"\n"})
}
/**
* helper:
* - format a message with information about a successful network request
* - save the binary data Buffer to disk
**/
const process_binary_success = function({url, redirects, response}, filename){
log((
`${sep}${sep}
URL of initial request:
${url}
Chain of URL redirects:
${(redirects && redirects.length) ? redirects.join("\n ") : '[]'}`
), {post:"\n\n"})
fs.writeFile(filename, response, 'binary')
.then(() => {
log(['Binary data Buffer saved to file:', filename], {div:"\n ", post:"\n\n"})
})
.catch((error) => {
log(['Error: Failed to save binary data Buffer to file:', filename], {div:"\n ", post:"\n\n"})
log(['Error message:', error.message], {div:"\n ", post:"\n\n"})
})
}
/**
* helper:
* - format a message with information about a successful network request
* - save the binary data stream to disk
**/
const process_binary_stream_success = function({url, redirects, response}, filename){
log((
`${sep}${sep}
URL of initial request:
${url}
Chain of URL redirects:
${(redirects && redirects.length) ? redirects.join("\n ") : '[]'}`
), {post:"\n\n"})
response
.pipe( fs.createWriteStream(filename) )
.on('finish', () => {
log(['Binary data Stream saved to file:', filename], {div:"\n ", post:"\n\n"})
})
.on('error', (error) => {
log(['Error: Failed to save binary data Stream to file:', filename], {div:"\n ", post:"\n\n"})
log(['Error message:', error.message], {div:"\n ", post:"\n\n"})
response.destroy()
})
}
/**
* helper:
* - format an error message
**/
const process_error = function(error){
log((
`${sep}${sep}
Error:
${error.message}
HTTP status code:
${error.statusCode ? error.statusCode : 'unavailable'}
URL of initial request:
${error.url ? error.url : 'unavailable'}
Chain of URL redirects:
${(error.redirects && error.redirects.length) ? error.redirects.join("\n ") : '[]'}
Unfollowed redirect:
${error.location ? error.location : 'none'}`
), {post:"\n\n"})
}
// example: perform a request that succeeds after performing 2 redirects and changing protocol from 'http' to 'https'
request('http://github.com/warren-bank/node-denodeify/raw/master/package.json')
.then(process_text_success)
.catch(process_error)
// example: perform the same request but configure the maximum number of permitted redirects to result in an Error
request('http://github.com/warren-bank/node-denodeify/raw/master/package.json', '', {maxRedirects: 1})
.then(process_text_success)
.catch(process_error)
// example: perform a request that succeeds after performing 1 redirect and retrieves binary data in a Buffer
request('https://github.com/warren-bank/node-denodeify/archive/master.zip', '', {binary: true})
.then((data) => {process_binary_success(data, 'denodeify.Buffer.zip')})
.catch(process_error)
// example: perform the same request but retrieve the binary data from a Readable stream
request('https://github.com/warren-bank/node-denodeify/archive/master.zip', '', {binary: true, stream: true})
.then((data) => {process_binary_stream_success(data, 'denodeify.Stream.zip')})
.catch(process_error)
These HTTP method convenience functions act just like request() but with a default method:
method: "GET".method: "POST".method: "PUT".method: "PATCH".method: "DELETE".method: "HEAD".method: "OPTIONS".@warren-bank/node-denodeifyFAQs
An extremely lightweight HTTP request client. Supports: http, https, redirects, cookies, content-encoding, multipart/form-data. Returns: Promise.
We found that @warren-bank/node-request demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.