https://github.com/rwv/get-cloudflare-location
☁ A JavaScript function to get user's location based on Cloudflare /cdn-cgi/trace
https://github.com/rwv/get-cloudflare-location
browser cloudflare javascript location network
Last synced: over 1 year ago
JSON representation
☁ A JavaScript function to get user's location based on Cloudflare /cdn-cgi/trace
- Host: GitHub
- URL: https://github.com/rwv/get-cloudflare-location
- Owner: rwv
- License: mit
- Archived: true
- Created: 2023-07-12T00:49:09.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-17T06:30:40.000Z (over 1 year ago)
- Last Synced: 2025-03-01T17:11:52.826Z (over 1 year ago)
- Topics: browser, cloudflare, javascript, location, network
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/get-cloudflare-location
- Size: 291 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ☁️ get-cloudflare-location
> [!CAUTION]
> `https://cf-ns.com/cdn-cgi/trace` returns `404 Not Found` now. **Don't** use this package!
A JavaScript function to get user's location based on Cloudflare `/cdn-cgi/trace`
[](https://github.com/rwv/get-cloudflare-location/actions/workflows/build.yml)
[](https://www.npmjs.com/package/get-cloudflare-location)

## How it works
This function will send a request to `https://www.cloudflare.com/cdn-cgi/trace` and `https://cf-ns.com/cdn-cgi/trace` and parse the response to get the user's location.
## Usage
```bash
npm install get-cloudflare-location
```
```ts
import getCloudflareLocation from "get-cloudflare-location";
interface GetCloudflareLocationOptions {
timeout?: number; // The timeout for the request in milliseconds. Defaults to 5000
cache?: string; // Whether to cache the result of the request. Defaults to true.
}
const options: GetCloudflareLocationOptions | undefined = {
timeout: 5000,
cache: true,
};
const location = await getCloudflareLocation(options);
```
## cf-ns.com
`cf-ns.com` is the domain of the Cloudflare China Network, allowing users in mainland China to get location in low latency.
## License
MIT