diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ecd440..8afb6d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +4.0.0 / 2023/11/07 +==================== +- **BREAKING**: This module is now ESM only. + - You will need to either migrate your projects to ESM, or import `got-scraping` in an async context via `await import('got-scraping');` +- Update `got` to v13 + 3.1.0 / 2021/08/23 ==================== - Add `sessionToken` option to persist generated headers diff --git a/README.md b/README.md index a8c78b3..c7ed263 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ $ npm install got-scraping ``` **Note:** -> - Node.js >=15.10.0 is required due to instability of HTTP/2 support in lower versions. +> This project is ESM only, which means it can only be imported using the `import` statement or the `import()` method. It is not possible to `require()` it. + +> - Node.js >=16 is required due to instability of HTTP/2 support in lower versions. ## API @@ -18,11 +20,22 @@ Got scraping package is built using the [`got.extend(...)`](https://github.com/s Interested what's [under the hood](#under-the-hood)? ```javascript -const { gotScraping } = require('got-scraping'); +import { gotScraping } from 'got-scraping'; gotScraping .get('https://apify.com') - .then( ({ body }) => console.log(body)) + .then( ({ body }) => console.log(body)); +``` + +```javascript +// If you're still using CJS and cannot use the import syntax +let gotScraping; + +async function fetchWithGotScraping(url) { + gotScraping ??= (await import('got-scraping')).gotScraping; + + return gotScraping.get(url); +} ``` ### options @@ -34,14 +47,14 @@ Type: **`string`** URL of the HTTP or HTTPS based proxy. HTTP/2 proxies are supported as well. ```javascript -const { gotScraping } = require('got-scraping'); +import { gotScraping } from 'got-scraping'; gotScraping .get({ url: 'https://apify.com', proxyUrl: 'http://usernamed:password@myproxy.com:1234', }) - .then(({ body }) => console.log(body)) + .then(({ body }) => console.log(body)); ``` #### `useHeaderGenerator` diff --git a/package.json b/package.json index 32adf0f..1e2bff6 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "4.0.0", "description": "HTTP client made for scraping based on got.", "engines": { - "node": ">=18" + "node": ">=16" }, "files": [ "dist"