Production Deploy
Deploy your API to production.
Graceful Shutdown
typescript
const server = app.listen(PORT, () => { console.log(`🚀 Server running on port ${PORT}`);}); const gracefulShutdown = async (signal: string) => { console.log(`${signal} received. Shutting down...`); server.close(async () => { await prisma.$disconnect(); await redis.quit(); process.exit(0); }); setTimeout(() => process.exit(1), 30000);}; process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));process.on('SIGINT', () => gracefulShutdown('SIGINT'));Railway Deploy
bash
npm install -g @railway/clirailway loginrailway initrailway upGitHub Actions CI/CD
yaml
# .github/workflows/deploy.ymlname: Deploy on: push: branches: [main] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - run: npm ci - run: npm test deploy: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Deploy to Railway uses: bervProject/railway-deploy@main with: railway_token: ${{ secrets.RAILWAY_TOKEN }}PM2 for Production
javascript
// ecosystem.config.jsmodule.exports = { apps: [{ name: 'ecommerce-api', script: 'dist/server.js', instances: 'max', exec_mode: 'cluster', env_production: { NODE_ENV: 'production' }, }],};Deploy Checklist
- ✅ Tests passing
- ✅ Environment variables set
- ✅ Migrations executed
- ✅ HTTPS configured
- ✅ Monitoring active
Summary
- ✅ Graceful shutdown
- ✅ Railway/Render deploy
- ✅ CI/CD with GitHub Actions
Next lesson: E-commerce Project - Part 1! 🚀