![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@cfworker/web
Advanced tools
Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify
Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify.
import { Application, Middleware, Router, validate } from '@cfworker/web';
const router = new Router();
// Add the homepage route.
router.get('/', ({ res }) => {
res.body = `
<h1>@cfworker/web demo</h1>
<h2 id="example-routes">Example routes</h2>
<ol aria-labelledby="example-routes">
<li><a href="/greetings/hello">A valid greeting</a></li>
<li><a href="/greetings/hell">An invalid greeting</a></li>
<li><a href="/error">A route with a bug</a></li>
</ol>
<img src="favicon.ico" alt="cfworker logo">`;
});
// Add a greeting route with validation.
router.get(
'/greetings/:greeting',
validate({
params: {
required: ['greeting'],
properties: {
greeting: {
minLength: 5,
maxLength: 10
}
}
}
}),
({ req, res }) => {
res.body = req.params;
}
);
// Add a route to demonstrate exception handling.
router.get('/error', () => {
// @ts-ignore - this route has a bug!
req.this.method.does.not.exist();
});
// Favicon route for fun :)
router.get('/favicon.ico', ({ res }) => {
res.type = 'image/svg+xml';
res.body = `
<svg xmlns="http://www.w3.org/2000/svg" baseProfile="full" width="200" height="200">
<rect width="100%" height="100%" fill="#F38020"/>
<text font-size="120" font-family="Arial, Helvetica, sans-serif" text-anchor="end" fill="#FFF" x="185" y="185">W</text>
</svg>`;
});
// Simple CORS middleware.
const cors: Middleware = async ({ res }, next) => {
res.headers.set('access-control-allow-origin', '*');
await next();
};
// Compose the application
new Application().use(cors).use(router.middleware).listen();
git clone https://github.com/cfworker/cfworker
cd cfworker
yarn install
yarn workspace @cfworker/web cfworker run examples/worker.ts --watch --nocheck
FAQs
Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify
The npm package @cfworker/web receives a total of 45 weekly downloads. As such, @cfworker/web popularity was classified as not popular.
We found that @cfworker/web demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.