Generate and deploy serverless functions on Vercel with proper configuration for Node.js, Python, Edge, or other runtimes
Generates and configures Vercel serverless or edge functions with proper runtime settings, environment variables, and deployment configuration.
This skill helps you create production-ready Vercel Functions with:
When the user requests Vercel function deployment:
1. **Determine Function Type**
- Ask what the function should do (API endpoint, webhook, cron job, background task, edge middleware)
- Identify if it needs streaming, long duration, or edge runtime
- Check if it requires external APIs, databases, or third-party services
2. **Choose Runtime**
- Node.js: Default for most use cases, supports npm packages
- Edge Runtime: Ultra-fast, globally distributed, limited APIs
- Python: ML/data processing, scientific computing
- Bun: High-performance JavaScript alternative
- Go, Ruby, Rust: Specialized workloads
- Read `vercel.json` or project files to detect existing runtime preferences
3. **Create Function Files**
- For Node.js API routes: Create `api/[name].js` or `api/[name].ts`
- For Edge functions: Create `middleware.ts` or use Edge Runtime config
- For Python: Create `api/[name].py` with proper handler signature
- Ensure proper export format: `export default function handler(req, res)` (Node.js) or equivalent
4. **Configure Function Settings**
- Check if custom settings needed in `vercel.json`:
- `maxDuration`: Set if function needs >10s (requires Pro/Enterprise)
- `memory`: Adjust if heavy computation (1024 MB, 3008 MB options)
- `regions`: Specify if geo-targeting needed (default: all)
- Add runtime-specific config if using advanced features
- Example `vercel.json`:
```json
{
"functions": {
"api/long-task.js": {
"maxDuration": 60,
"memory": 3008
},
"api/edge.js": {
"runtime": "edge"
}
}
}
```
5. **Handle Environment Variables**
- Identify required secrets (API keys, database URLs)
- Check `.env.local` for local values
- Remind user to add via Vercel Dashboard or CLI:
- `vercel env add SECRET_NAME production`
- Use `process.env.SECRET_NAME` in code
- Never hardcode sensitive values
6. **Add Error Handling & Logging**
- Wrap logic in try-catch blocks
- Return proper HTTP status codes (200, 400, 500)
- Log errors for observability: `console.error()`
- Set appropriate CORS headers if needed
7. **Test Locally**
- Run `vercel dev` to test function locally
- Verify environment variables load correctly
- Test edge cases and error scenarios
- Check response format matches expectations
8. **Deploy**
- If Git integration active: Commit and push to trigger deploy
- If manual deploy: Run `vercel --prod` from project root
- Provide deployment URL from output
- Monitor deployment logs for errors
9. **Verify Deployment**
- Test the function URL in production
- Check Vercel Dashboard > Logs for runtime errors
- Verify environment variables are set correctly
- Set up monitoring/alerts if needed via Vercel Observability
10. **Document Function**
- Add comments explaining function purpose
- Document required environment variables in README
- Note any rate limits or usage considerations
- Provide example request/response
```javascript
// api/hello.js
export default function handler(req, res) {
const { name = 'World' } = req.query;
res.status(200).json({ message: `Hello, ${name}!` });
}
```
```typescript
// api/stream.ts
export const config = { runtime: 'edge' };
export default async function handler(req: Request) {
const encoder = new TextEncoder();
const stream = new ReadableStream({
start(controller) {
controller.enqueue(encoder.encode('Streaming response...'));
controller.close();
}
});
return new Response(stream);
}
```
```python
from http.server import BaseHTTPRequestHandler
import json
class handler(BaseHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length)
data = json.loads(body)
# Process data
result = {"processed": True, "data": data}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(result).encode())
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/deploy-vercel-serverless-functions/raw