Send a text to yourself from Express
Yes. Homing Pigeon (homingpigeon.dev) lets your Express app text your phone from any route, like when a new order comes in, and from your error middleware when a request fails. The text is sent in the background, so no response waits on it, and your coding agent can add it to the app you already have.
What to tell your agent
Use Homing Pigeon to text me from this Express app when a new order comes in or a request fails.
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. Add this helper as text-me.js. It reads your key from HOMINGPIGEON_API_KEY, and it never throws, so a route can call it without await:
function textMe(message, idempotencyKey) {
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(5000)
})
.then(async (res) => {
if (!res.ok) console.warn("Text alert failed:", (await res.json()).error.message);
})
.catch((err) => console.warn("Text alert failed:", err.message));
}
module.exports = { textMe };
Then call it from a route, and add error middleware after all your routes, so a request that fails with a server error texts you too. Replace saveOrder with your own code and use your own fields:
const express = require("express");
const { textMe } = require("./text-me");
const app = express();
app.use(express.json());
app.post("/orders", async (req, res, next) => {
try {
const order = await saveOrder(req.body);
textMe(`New order ${order.id} for $${order.total}.`, `order-${order.id}`);
res.status(201).json(order);
} catch (err) {
next(err);
}
});
app.use((err, req, res, next) => {
const status = err.status || err.statusCode || 500;
if (status >= 500) {
const hour = new Date().toISOString().slice(0, 13);
textMe(`${req.method} ${req.path.slice(0, 100)} failed: ${String(err.message).slice(0, 200)}`, `error-${hour}`);
console.error(err);
}
if (res.headersSent) return next(err);
res.status(status).json({ error: status >= 500 ? "Something went wrong." : err.message });
});
app.listen(3000);
Good to know
- There is no
awaitin front oftextMe, so the response goes out right away and the text is sent in the background. If a send fails or takes longer than 5 seconds, the reason goes to your server log and the request is not affected. - The error text reads like "POST /orders failed: database timed out after 30 s." The path is cut to 100 characters and the error to 200, because messages are limited to 480, and
req.pathleaves out the query string, so anything in it stays out of your texts. - Only errors with a status of 500 or more text you. A request with malformed JSON gets a 400 from
express.json, and any error you give astatusbelow 500 stays quiet too, so a bad request from a visitor never reaches your phone. - The hour in the idempotency key means you get at most one error text an hour, even if every request is failing, so a broken database cannot use up your texts. A different error later in the same hour stays quiet as well, so check your server log, where
console.errorwrites each one, once you get a text. - The order ID in the idempotency key means a retried request never texts you twice for the same order.
- Express knows error middleware by its four arguments, so keep
nexteven though it is rarely used. Add it withapp.useafter all your routes and other middleware, or it never sees their errors. If the response has already started, it hands the error to Express's default handler, which closes the connection. - Express 5 passes errors from an async route to
nexton its own, while Express 4 needs thetryandcatchshown here. Without them, an error in an Express 4 async route never reaches your error middleware. - Fire-and-forget suits a server that keeps running, such as a VPS or a container. On a serverless host that can freeze the function once the response is sent, put
returnin front offetchin the helper andawaitin front of eachtextMecall, and make the error middlewareasync. It still never throws. - Verify your phone with
npx -y homingpigeondev verify +15551234567, then again with the six-digit code it texts you.npx -y homingpigeondev keythen prints your key. Set it asHOMINGPIGEON_API_KEYin your server's environment and keep it out of git. - Messages 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.