send-beacon
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Beacon API for Node.js

The Beacon API is used to send an asynchronous and non-blocking request to a web server. The request does not expect a response.

Usage

Instead of using http get which would prevent Node.js process from exiting:

// This will prevent Node.js process from exit for 3 seconds
const http = require('http')
http.get('https://timeout.now.sh/3000')

Use sendBeacon:

// Fire and forget, Node.js process exit immediately
const sendBeacon = require('send-beacon')
sendBeacon('https://timeout.now.sh/3000')

Also you may send post request:

const sendBeacon = require('send-beacon')
sendBeacon('https://timeout.now.sh/3000', '{"key": "value"}')

Package Sidebar

Install

npm i send-beacon

Weekly Downloads

3

Version

0.0.3

License

MIT

Unpacked Size

2.27 kB

Total Files

4

Last publish

Collaborators

  • amio