Agent SkillsAgent Skills
secondsky

cloudflare-workers-migration

@secondsky/cloudflare-workers-migration
secondsky
133
19 forks
Updated 5/5/2026
View on GitHub

Migrate to Cloudflare Workers from AWS Lambda, Vercel, Express, and Node.js. Use when porting existing applications to the edge, adapting serverless functions, or resolving Node.js API compatibility issues.

Installation

$npx agent-skills-cli install @secondsky/cloudflare-workers-migration
Claude Code
Cursor
Copilot
Codex
Antigravity

Details

Pathplugins/cloudflare-workers/skills/cloudflare-workers-migration/SKILL.md
Branchmain
Scoped Name@secondsky/cloudflare-workers-migration

Usage

After installing, this skill will be available to your AI coding assistant.

Verify installation:

npx agent-skills-cli list

Skill Instructions


name: cloudflare-workers-migration description: Migrate to Cloudflare Workers from AWS Lambda, Vercel, Express, and Node.js. Use when porting existing applications to the edge, adapting serverless functions, or resolving Node.js API compatibility issues. metadata: version: "1.0.0" license: MIT

Workers Migration Guide

Migrate existing applications to Cloudflare Workers from various platforms.

Migration Decision Tree

What are you migrating from?
├── AWS Lambda
│   └── Node.js handler? → Lambda adapter pattern
│   └── Python? → Consider Python Workers
│   └── Container/custom runtime? → May need rewrite
├── Vercel/Next.js
│   └── API routes? → Minimal changes with adapter
│   └── Full Next.js app? → Use OpenNext adapter
│   └── Middleware? → Direct Workers equivalent
├── Express/Node.js
│   └── Simple API? → Hono (similar API)
│   └── Complex middleware? → Gradual migration
│   └── Heavy node: usage? → Compatibility layer
└── Other Edge (Deno Deploy, Fastly)
    └── Standard Web APIs? → Minimal changes
    └── Platform-specific? → Targeted rewrites

Platform Comparison

FeatureWorkersLambdaVercelExpress
Cold Start~0ms100-500ms10-100msN/A
CPU Limit50ms/10ms15 min10sNone
Memory128MB10GB1GBSystem
Max Response6MB (stream unlimited)6MB4.5MBNone
Global Edge300+ PoPsRegional~20 PoPsManual
Node.js APIsPartialFullFullFull

Top 10 Migration Errors

ErrorFromCauseSolution
fs is not definedLambda/ExpressFile system accessUse KV/R2 for storage
Buffer is not definedNode.jsNode.js globalsImport from node:buffer
process.env undefinedAllEnv access patternUse env parameter
setTimeout not returningLambdaAsync patternsUse ctx.waitUntil()
require() not foundExpressCommonJSConvert to ESM imports
Exceeded CPU timeAllLong computationChunk or use DO
body already consumedExpressRequest bodyClone before read
Headers not iterableLambdaHeaders APIUse Headers constructor
crypto.randomBytesNode.jsNode cryptoUse crypto.getRandomValues
Cannot find moduleAllMissing polyfillCheck Workers compatibility

Quick Migration Patterns

AWS Lambda Handler

// Before: AWS Lambda
export const handler = async (event, context) => {
  const body = JSON.parse(event.body);
  return {
    statusCode: 200,
    body: JSON.stringify({ message: 'Hello' }),
  };
};

// After: Cloudflare Workers
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const body = await request.json();
    return Response.json({ message: 'Hello' });
  },
};

Express Middleware

// Before: Express
app.use((req, res, next) => {
  if (!req.headers.authorization) {
    return res.status(401).json({ error: 'Unauthorized' });
  }
  next();
});

// After: Hono Middleware
app.use('*', async (c, next) => {
  if (!c.req.header('Authorization')) {
    return c.json({ error: 'Unauthorized' }, 401);
  }
  await next();
});

Environment Variables

// Before: Node.js
const apiKey = process.env.API_KEY;

// After: Workers
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const apiKey = env.API_KEY;
    // ...
  },
};

Node.js Compatibility

Workers support many Node.js APIs via compatibility flags:

// wrangler.jsonc
{
  "compatibility_flags": ["nodejs_compat_v2"],
  "compatibility_date": "2024-12-01"
}

Supported with nodejs_compat_v2:

  • crypto (most methods)
  • buffer (Buffer class)
  • util (promisify, types)
  • stream (Readable, Writable)
  • events (EventEmitter)
  • path (all methods)
  • string_decoder
  • assert

Not Supported (need alternatives):

  • fs → Use R2/KV
  • child_process → Not possible
  • cluster → Not applicable
  • dgram → Not supported
  • net → Use fetch/WebSocket
  • tls → Handled by platform

When to Load References

ReferenceLoad When
references/lambda-migration.mdMigrating AWS Lambda functions
references/vercel-migration.mdMigrating from Vercel/Next.js
references/express-migration.mdMigrating Express/Node.js apps
references/node-compatibility.mdNode.js API compatibility issues

Migration Checklist

  1. Analyze Dependencies: Check for unsupported Node.js APIs
  2. Convert to ESM: Replace require() with import
  3. Update Env Access: Use env parameter instead of process.env
  4. Replace File System: Use R2/KV for storage
  5. Handle Async: Use ctx.waitUntil() for background tasks
  6. Test Locally: Verify with wrangler dev
  7. Performance Test: Ensure CPU limits aren't exceeded

See Also

  • workers-runtime-apis - Available APIs in Workers
  • workers-performance - Optimization techniques
  • cloudflare-worker-base - Basic Workers setup

More by secondsky

View all
sap-api-style
242

This skill provides comprehensive guidance for documenting SAP APIs following the SAP API Style Guide standards. It should be used when creating or reviewing API documentation for REST, OData, Java, JavaScript, .NET, or C/C++ APIs. The skill covers naming conventions, documentation comments, OpenAPI specifications, quality checklists, deprecation policies, and manual documentation templates. It ensures consistency with SAP API Business Hub standards and industry best practices. Keywords: SAP API, REST, OData, OpenAPI, Swagger, Javadoc, JSDoc, XML documentation, API Business Hub, API naming, API deprecation, x-sap-stateInfo, Entity Data Model, EDM, documentation tags, API quality, API templates

sap-btp-best-practices
242

Production-ready SAP BTP best practices for enterprise architecture, account management, security, and operations. Use when planning BTP implementations, setting up account hierarchies, configuring environments, implementing authentication, designing CI/CD pipelines, establishing governance, building Platform Engineering teams, implementing failover strategies, or managing application lifecycle on SAP BTP. Keywords: SAP BTP, account hierarchy, global account, directory, subaccount, Cloud Foundry, Kyma, ABAP, SAP Identity Authentication, CI/CD, governance, Platform Engineering, failover, multi-region, SAP BTP best practices

sap-abap
242

Comprehensive ABAP development skill for SAP systems. Use when writing ABAP code, working with internal tables, structures, ABAP SQL, object-oriented programming, RAP (RESTful Application Programming Model), CDS views, EML statements, ABAP Cloud development, string processing, dynamic programming, RTTI/RTTC, field symbols, data references, exception handling, or ABAP unit testing. Covers both classic ABAP and modern ABAP for Cloud Development patterns.

sap-btp-business-application-studio
242

This skill provides comprehensive guidance for SAP Business Application Studio (BAS), the cloud-based IDE on SAP BTP built on Code-OSS. Use when setting up BAS subscriptions, creating dev spaces, connecting to external systems, deploying MTA applications, troubleshooting connectivity issues, managing Git repositories, configuring runtime versions, or using the layout editor. Keywords: SAP Business Application Studio, BAS, SAP BTP, dev space, Cloud Foundry, MTA, multitarget application, SAP Fiori, CAP, HANA, destination, WebIDEEnabled, Cloud Connector, Service Center, Storyboard, Layout Editor, ABAP, OData, subscription, entitlements, role collection, Business_Application_Studio_Developer, Git, clone, push, pull, Gerrit, PAT, OAuth, asdf, runtime, Node.js, Java, Python, Task Explorer, CI/CD, Yeoman, generator, template wizard, mbt, mtar, debugging, breakpoint