Send a text message to yourself from Node.js

Yes. Homing Pigeon (homingpigeon.dev) lets any Node.js script text your own phone with one fetch call, built into Node 18 and later, so there is no package to install. Your coding agent can add it to the script you already have.

What to tell your agent

Use Homing Pigeon to text me from this Node.js script when it finishes.

Your agent asks for your number, you read back the six-digit code, and it does the rest.

How it works in code

Node 18 and later have fetch built in, so there is nothing to install. Set HOMINGPIGEON_API_KEY to your key, then put this where your script finishes its work:

async function textMe(message, idempotencyKey) {
  const res = await fetch("https://homingpigeon.dev/v1/send", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.HOMINGPIGEON_API_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ message, idempotency_key: idempotencyKey }),
    signal: AbortSignal.timeout(10000)
  });
  if (!res.ok) throw new Error(`Text alert failed: ${(await res.json()).error.message}`);
}

const today = new Date().toISOString().slice(0, 10);

textMe("Nightly import finished.", `import-${today}`).catch((err) => {
  console.error(err.message);
  process.exitCode = 1;
});

For one-liners in npm scripts, run npm install --save-dev homingpigeondev in your project. npm puts the homingpigeon command on the PATH for your scripts, so in package.json:

{
  "scripts": {
    "import": "node import.js || homingpigeon send \"Import failed.\"",
    "train": "node train.js; homingpigeon send \"Training finished with exit code $?\""
  }
}

Good to know

  • Verify your phone with npx homingpigeon verify +15551234567, then again with the six-digit code it texts you. The key is saved in your home folder, where the command finds it. npx homingpigeon key prints it for HOMINGPIGEON_API_KEY, and if that variable is set, the command uses it instead.
  • On Node 20.6 and later, node --env-file=.env import.js loads HOMINGPIGEON_API_KEY from a .env file. Keep that file out of git.
  • The date in the idempotency key means a rerun on the same day never texts you twice. Use a job ID instead when you want one text per job.
  • If Homing Pigeon rejects a send, such as a message over 480 characters, textMe throws with its reason. The .catch prints it and sets the exit code to 1, so a failed text shows in your logs instead of crashing the script. The 10-second timeout keeps a slow network from holding the script open.
  • To call textMe from several files, move it to its own file and end that file with module.exports = { textMe };. In an ES module, write export async function textMe instead.
  • In package.json, || texts you only when node import.js exits with an error. ; texts you either way, and $? puts the exit code in the text, where 0 means it worked. Both work where npm runs scripts with sh, on macOS and Linux.
  • Both scripts end with the send, so npm run reports success once the text goes out, even if the job failed. If CI or another script needs the job's real exit code, call textMe from inside your script instead.
  • Messages are limited to 480 characters and go only to the US mobile number you verified. Keep them plain, with no links. Delivery is not guaranteed, so treat each text as a heads-up.

Get started

Add Homing Pigeon to Claude Code, then ask for what you want:

claude mcp add homingpigeondev -- npx -y homingpigeondev mcp

You get 50 free texts every month, on US mobile numbers. See more use cases.