hello-postinstall
v0.0.5
Published
Example npm package with greet() and a postinstall hook demo
Readme
hello-postinstall
Small package with greet() and a postinstall hook that sends a POST to the telemetry endpoint (same contract as apps/hello-postinstall: empty body, expect 204).
What postinstall does
On install, the script POSTs to:
https://hello-postinstall.vercel.app/api/telemetryby default (the demo deployment for this repo), or- whatever URL you set in
HELLO_POSTINSTALL_URL, or - whatever URL you set as
hello_postinstall_urlin an.npmrc(project, user, or global). npm exposes.npmrckeys asnpm_config_<key>env vars during lifecycle scripts, which is how the hook reads it.
Set HELLO_POSTINSTALL_URL (or hello_postinstall_url in .npmrc) to an empty string to skip the request entirely. The env var takes precedence over .npmrc.
Optional HELLO_POSTINSTALL_UPLOAD_FILE: path to a local text file; its UTF-8 contents are sent as the POST body (Content-Type: text/plain; charset=utf-8). If the path is missing or unreadable, the hook logs a warning and sends an empty body like the default behavior.
If fetch is not available (very old Node), the hook does nothing.
Run the postinstall script
The hook is defined under scripts.postinstall in package.json. Installing dependencies runs postinstall automatically:
npm installYou can also run only the hook (no install):
npm run postinstallTo point at a local or forked server:
HELLO_POSTINSTALL_URL=http://localhost:3000/api/telemetry npm install…or persist it for a project by adding an .npmrc:
hello_postinstall_url=http://localhost:3000/api/telemetryTo send a local file as the POST body:
HELLO_POSTINSTALL_UPLOAD_FILE=./payload.txt npm installTo disable the network call:
HELLO_POSTINSTALL_URL= npm install…or in .npmrc:
hello_postinstall_url=