Skip to content

js-bits/fetch

Repository files navigation

Cross-environment (nodejs/web) fetch APi

This package exports window.fetch object in a browser and node-fetch module in a Node.js environment. Which is helpful when you develop a package compatible with both environments and use fetch for HTTP requests. Allows to avoid conditional imports.

Installation

Install with npm:

npm install @js-bits/fetch

Install with yarn:

yarn add @js-bits/fetch

Import where you need it:

import fetch from '@js-bits/fetch';

or require for CommonJS:

const fetch = require('@js-bits/fetch');

How to use

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));

Notes

About

Cross-environment (nodejs/web) fetch API

Resources

Stars

Watchers

Forks

Packages

No packages published