Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-fetch-commonjs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-fetch-commonjs

A light-weight module that brings Fetch API to node.js

  • 3.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is node-fetch-commonjs?

The node-fetch-commonjs package is a CommonJS version of the popular node-fetch library, which allows you to make HTTP requests in a Node.js environment. It provides a simple and familiar API for making network requests, similar to the Fetch API available in browsers.

What are node-fetch-commonjs's main functionalities?

Basic GET Request

This feature allows you to make a basic GET request to a specified URL and handle the response. The example fetches a post from a placeholder API and logs the response data.

const fetch = require('node-fetch-commonjs');

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 example sends a new post to a placeholder API and logs the response data.

const fetch = require('node-fetch-commonjs');

const data = { title: 'foo', body: 'bar', userId: 1 };

fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(data)
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Handling Headers

This feature allows you to include custom headers in your requests. The example fetches a post from a placeholder API with an Authorization header.

const fetch = require('node-fetch-commonjs');

fetch('https://jsonplaceholder.typicode.com/posts/1', {
  headers: { 'Authorization': 'Bearer token' }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Other packages similar to node-fetch-commonjs

Keywords

FAQs

Package last updated on 12 Sep 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc