Urgent.News

What's breaking now, across thousands of outlets.

Tech

Deploy a Node/TypeScript API to Railway in 15 minutes (with a worker-friendly setup)

This walkthrough deploys a simple Express API to Railway, sets env vars, and notes how to add a second service later for a queue worker. Disclosure: Some links are affiliate links. I may earn a commission at no extra cost to you. What you'll end up with A deployed Node/TS HTTP service HTTPS URL on Railway Env-based config ( PORT , DATABASE_URL , etc.) A clear path to add a worker process (BullMQ…

This guide details deploying a simple Express API to Railway, complete with environment variables and a step-by-step process for adding a second service to act as a queue worker. Railway will automatically set the PORT environment variable, so you won't need to hardcode it in your production environment. The tutorial provides a companion GitHub repository, which can be cloned or forked for immediate deployment.

Prerequisites include having Node 20 or later installed locally, as well as a GitHub repository or access to the Railway CLI. The process should take approximately 15 minutes to complete.

First, create a minimal API in your project's `src/index.ts` file, where you import the Express framework, set the port based on the environment variable or default to 3000, and define a health check endpoint. Your `package.json` should include build, start, and development scripts relevant to building and running your TypeScript application.

Next, sign up or log into Railway using the provided link, which includes starter credits under certain conditions. From there, deploy your GitHub repository directly to Railway by selecting the repo and root directory. Once the deployment is set up, configure the necessary environment variables, ensuring you never commit sensitive information to your repository and rotate any shared secrets.

Once the service is live, access the generated Railway domain (or a custom domain) and verify the health check endpoint returns `{ "ok": true }`. If you plan to add a queue worker later, you can create a second Railway service from the same repository, adjusting the start command accordingly. Remember to share environment variables and potentially use Redis as a plugin or an external service.

Be mindful of cost implications, especially when starting out, and separate your web service and worker service to prevent one from affecting the other.

Cost considerations for solo developers suggest starting with the smallest possible deployment and monitoring usage closely. Separating your web service and worker allows for more controlled resource allocation. Railway is best suited for solo or small teams needing a Node/TS API with optional background processing. However, it may not be the ideal choice for applications requiring multi-region deployment capabilities.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Friday 11 September →