Day 5 of 5
⏱ ~60 minutes
Build an AI Chatbot — Day 5

Deploy Your Chatbot: Railway, Environment Variables, and Going Live

Day 5 deploys your chatbot to the internet with a public URL. You will use Railway for zero-config Node.js deployment.

Deploying to Railway

Railway is the fastest way to deploy a Node.js app. Free tier is generous enough for a personal chatbot. Connect your repo, set environment variables, and it deploys automatically.

package.json — Add Start Script
{
  "scripts": {
    "start": "node server.js"
  }
}
Deployment Steps
# 1. Initialize git if you haven't
git init
git add .
git commit -m "Initial chatbot"

# 2. Create a .gitignore
echo "node_modules/
.env" > .gitignore

# 3. Push to GitHub
git remote add origin your-repo-url
git push -u origin main

# 4. Go to railway.app
# - New Project → Deploy from GitHub repo
# - Select your repo
# - Add environment variable: ANTHROPIC_API_KEY
# - Railway auto-detects Node.js and deploys

Production Hardening

Before sharing the URL publicly, add basic rate limiting and error handling:

server.js — Add Error Handling
// Wrap the API call in try/catch
app.post('/chat', async (req, res) => {
  try {
    const { message, sessionId } = req.body;
    
    if (!message || message.length > 2000) {
      return res.status(400).json({ error: 'Invalid message' });
    }
    
    // ... rest of your code ...
    
  } catch (error) {
    console.error('Error:', error.message);
    res.status(500).json({ 
      error: 'Something went wrong. Please try again.' 
    });
  }
});
ℹ️
API costs: The Claude API charges per token. A typical conversation message costs a fraction of a cent. For a personal or small business chatbot with moderate traffic, monthly costs are usually under $5-10. Monitor your usage at console.anthropic.com.
Day 5 Exercise
Deploy and Share Your Chatbot
  1. Add the start script to package.json and create .gitignore.
  2. Push your code to a GitHub repository (public or private).
  3. Deploy to Railway and set the ANTHROPIC_API_KEY environment variable.
  4. Test the live URL — does everything work the same as local?
  5. Share the URL with one person. Get their feedback on the chatbot's usefulness.

Course Complete — What You've Built

  • A full-stack AI chatbot: Node.js backend, clean chat UI, conversation history, and a custom system prompt.
  • RAG integration to answer questions from your own documents without hallucination.
  • A deployed URL on Railway with error handling and environment variables properly managed.
  • A foundation for adding features: streaming, user auth, database-backed history, custom document loading.

Want to go deeper in 3 days?

Our in-person AI bootcamp covers advanced AI development, agentic systems, and production deployment. Five cities. $1,490.

Reserve Your Seat →
Finished this lesson?