Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@whatwg-node/node-fetch
Advanced tools
@whatwg-node/node-fetch is a Node.js implementation of the Fetch API, which is a modern, promise-based way to make HTTP requests. It is designed to be a lightweight and efficient way to handle HTTP requests and responses, similar to the Fetch API available in web browsers.
Basic GET Request
This feature allows you to make a basic GET request to a specified URL and handle the response. The response is converted to JSON and logged to the console.
const fetch = require('@whatwg-node/node-fetch');
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
POST Request with JSON Body
This feature allows you to make a POST request with a JSON body. The request includes headers to specify the content type and a body with the data to be sent.
const fetch = require('@whatwg-node/node-fetch');
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'foo',
body: 'bar',
userId: 1
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Handling Response Headers
This feature demonstrates how to access and log the response headers from an HTTP request. The headers are logged before the response body is processed.
const fetch = require('@whatwg-node/node-fetch');
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(response => {
console.log('Headers:', response.headers.raw());
return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
node-fetch is another implementation of the Fetch API for Node.js. It is widely used and has a similar API to @whatwg-node/node-fetch. However, node-fetch is more mature and has a larger user base.
axios is a promise-based HTTP client for Node.js and the browser. It provides a more feature-rich API compared to @whatwg-node/node-fetch, including support for request and response interceptors, automatic JSON transformation, and more.
got is a human-friendly and powerful HTTP request library for Node.js. It offers a more extensive set of features compared to @whatwg-node/node-fetch, such as retry mechanisms, advanced error handling, and support for streams.
FAQs
Fetch API implementation for Node
The npm package @whatwg-node/node-fetch receives a total of 5,524,355 weekly downloads. As such, @whatwg-node/node-fetch popularity was classified as popular.
We found that @whatwg-node/node-fetch 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.