Sign inGet Started

Node.js SDK

Send email with Railway

Deploy a small Parcel Wing-powered email service on Railway using environment variables for secrets.

Install the SDK

The official SDK is published as @parcelwing/node.

Terminal

npm install @parcelwing/node

Variables

Add your Parcel Wing API key and default sender to Railway Variables. Railway exposes service variables to your app at runtime as environment variables.

Railway Variables

PARCEL_WING_API_KEY=pw_live_...
PARCEL_WING_FROM_EMAIL="Acme <[email protected]>"

Email endpoint

Create a small server that reads Railway's PORT variable and sends mail from a trusted backend endpoint.

src/server.ts

import express from "express";
import { ParcelWing, ParcelWingError } from "@parcelwing/node";
 
const app = express();
const parcelWing = new ParcelWing({
apiKey: process.env.PARCEL_WING_API_KEY!,
});
 
app.use(express.json());
 
app.get("/health", (_req, res) => {
res.json({ ok: true });
});
 
app.post("/send", async (req, res) => {
try {
const [message] = await parcelWing.emails.send({
from: process.env.PARCEL_WING_FROM_EMAIL!,
to: req.body.email,
template_alias: "welcome_email",
template_params: {
first_name: req.body.firstName ?? "friend",
},
});
 
res.json({ id: message?.id });
} catch (error) {
if (error instanceof ParcelWingError) {
res.status(error.status).json({
code: error.code,
requestId: error.requestId,
});
return;
}
 
res.status(500).json({ error: "Unexpected error" });
}
});
 
const port = Number(process.env.PORT ?? 3000);
app.listen(port, () => {
console.log("Server listening on " + port);
});

Deployment

Use a build script and start script so Railway can build TypeScript and run the compiled server.

package.json

{
"scripts": {
"start": "node dist/server.js",
"build": "tsc"
},
"dependencies": {
"@parcelwing/node": "latest",
"express": "latest"
},
"devDependencies": {
"@types/express": "latest",
"typescript": "latest"
}
}

Production notes

  • Keep PARCEL_WING_API_KEY in Railway Variables, not in source control.
  • Add authentication, rate limiting, or bot protection before exposing public sending endpoints.
  • Use a verified sending domain before sending production email.