← Back
Backend Setup Guide
Follow these steps to deploy the backend on Railway (free tier works). The frontend stays on Vercel.
The backend requires ffmpeg and yt-dlp to run — Railway auto-installs both via the railway.toml config below. You don't need to install anything manually on the server.
Live Backend Diagnostics— click to test your Railway server right now
Deploy Instructions
WHY THIS WORKS:
Your Railway server's IP is flagged by YouTube. Cookies tie the request to YOUR real
Google account — YouTube can't block that without blocking you personally.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🚨 STILL NOT WORKING? START HERE — DO THIS FIRST:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 0 — CHECK IF RAILWAY IS EVEN RUNNING THE NEW CODE
────────────────────────────────────────────────────────────────
Visit this URL in your browser RIGHT NOW:
https://YOUR-BACKEND.up.railway.app/api/version
✅ NEW code running: {"version":"v2-cookies","built":"2024-cookies-fix"}
❌ OLD code running: 404 Not Found (or any other response)
If you get 404 → Railway is 100% still running OLD code. The problem is NOT
your cookies.txt location — it doesn't even matter yet until new code runs.
─── HOW TO FORCE RAILWAY TO USE YOUR NEW CODE ────────────────────────────────
Option A — Force redeploy from Railway dashboard:
1. Go to railway.app → your backend service
2. Click "Deployments" tab on the left
3. Find the latest deployment → click the "..." (3 dots) → click "Redeploy"
4. Wait 2 minutes → check /api/version again
Option B — Trigger a new deploy via GitHub:
1. Open index.js in your GitHub repo
2. Click the pencil (edit) icon
3. Add a comment anywhere: // v2-cookies-fix
4. Click "Commit changes"
5. Railway detects the push and rebuilds automatically (~2 min)
6. Check /api/version again
Option C — Check if Railway is connected to the right repo/branch:
1. Railway → your service → Settings tab
2. Under "Source" → confirm it shows your songslicer-backend repo
3. Confirm branch is "main" (not "master" or another branch)
4. If wrong branch, change it and redeploy
─── AFTER YOU CONFIRM NEW CODE IS RUNNING ────────────────────────────────────
Once /api/version returns {"version":"v2-cookies"...}, THEN check cookies:
────────────────────────────────────────────────────────────────
CHECKLIST ITEM 2 — Is your cookies.txt in the RIGHT folder in the repo?
────────────────────────────────────────────────────────────────
Railway deploys your GitHub repo root as /app/ on the server.
So the file must be at THIS path in your repo:
✅ CORRECT: [repo root]/cookies/cookies.txt
→ becomes /app/cookies/cookies.txt on server (FOUND!)
❌ WRONG: [repo root]/app/cookies/cookies.txt
→ becomes /app/app/cookies/cookies.txt on server (NOT FOUND!)
↑ THIS IS A COMMON MISTAKE. The "app" folder in your repo is
NOT the server's /app/. They are different things entirely.
❌ WRONG: [repo root]/cookies.txt
→ becomes /app/cookies.txt (NOT FOUND)
YOUR SITUATION: You have BOTH cookies/cookies.txt AND app/cookies/cookies.txt
in your repo. The correct one is cookies/cookies.txt at the repo ROOT.
The app/cookies/cookies.txt one does NOT help — delete it to avoid confusion.
─────────────────────────────────────────────────────────────────────
CHECKLIST ITEM 3 — Verify with the /api/debug endpoint
─────────────────────────────────────────────────────────────────────
Visit this in your browser (replace with your real Railway URL):
https://YOUR-BACKEND.up.railway.app/api/debug
Good result:
"/app/cookies/cookies.txt": "EXISTS (size: 13000+ bytes)"
Bad result:
"/app/cookies/cookies.txt": "NOT FOUND"
If NOT FOUND and your file IS at cookies/cookies.txt in the repo root,
the problem is that Railway hasn't redeployed yet with the new code
(the /api/debug endpoint only exists in the new index.js).
→ Force a redeploy (see Checklist Item 1 above).
─────────────────────────────────────────────────────────────────────
CHECKLIST ITEM 4 — cookies.txt IS NOT on the server. Here is why and the fix:
─────────────────────────────────────────────────────────────────────
The /api/debug endpoint proved the cookies folder does not exist on the server.
This means it was never committed + pushed to GitHub (or .gitignore blocked it).
THE FIX — run these commands in your terminal in your repo folder:
git add cookies/cookies.txt --force
git commit -m "add cookies"
git push
The --force flag bypasses .gitignore (which often blocks .txt files).
VERIFY it's actually on GitHub BEFORE waiting for Railway:
1. Go to github.com → your songslicer-backend repo
2. You should see a "cookies" folder listed in the file list
3. Click it — you should see cookies.txt inside
4. If it's NOT there → the push didn't work, try again
Once it's confirmed on GitHub → Railway auto-redeploys in ~2 min
→ Run Diagnostics again → should show COOKIES.TXT FOUND in green.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ RECOMMENDED METHOD — COOKIES_B64 Environment Variable
(Most reliable — bypasses all file/git/gitignore issues entirely)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WHY THIS IS BETTER THAN A FILE:
Railway environment variables are always deployed — no git, no gitignore,
no file path issues. Set it once and it just works.
STEP 1 — Get your cookies.txt content:
Install "Get cookies.txt LOCALLY" extension in Chrome/Firefox
Go to youtube.com while logged in → click extension → "Export As Netscape"
Save the file anywhere on your computer
STEP 2 — Convert cookies.txt to base64:
On Windows (PowerShell):
[Convert]::ToBase64String([IO.File]::ReadAllBytes("C:path ocookies.txt")) | clip
(this copies the base64 string straight to your clipboard)
On Mac/Linux (Terminal):
base64 -i cookies.txt | pbcopy (Mac — copies to clipboard)
base64 -i cookies.txt (Linux — prints to terminal, copy it)
STEP 3 — Add it to Railway as an environment variable:
Railway → your backend service → Variables tab → "New Variable"
Name: COOKIES_B64
Value: (paste the base64 string from Step 2)
Click "Add" → Railway auto-redeploys in ~1 min
STEP 4 — Verify it worked:
Run Diagnostics above → should show:
COOKIES_B64: SET (length: 18000+)
AND the download should now work!
─────────────────────────────────────────────────────────────────────
NOTE: Cookies expire every ~2 weeks. Re-export and repeat Steps 1-3.
NOTE: Your BGUTIL_URL is missing "https://" — fix that too (see below).
─────────────────────────────────────────────────────────────────────
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ALSO FIX: BGUTIL_URL is missing https://
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Your current BGUTIL_URL value is:
bgutil-ytdlp-pot-provider-production-7fba.up.railway.app ← WRONG (no https://)
Fix it in Railway → your main backend → Variables:
BGUTIL_URL = https://bgutil-ytdlp-pot-provider-production-7fba.up.railway.app
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
FALLBACK METHOD — cookies.txt via GitHub repo file
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
(Only use this if the env var method above doesn't work for some reason)
STEP 1 — In your terminal, in the repo folder:
git add cookies/cookies.txt --force
git commit -m "add cookies"
git push
(--force bypasses .gitignore)
STEP 2 — Verify on github.com that cookies/cookies.txt is visible in the repo
STEP 3 — Railway redeploys automatically, then run Diagnostics to confirm