![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
lark-router
Advanced tools
Router for lark based on koa 2.0
$ npm install --save lark-router
Lark-Router is a flexible and easy-to-use url router tool, compatible with native http apps, express apps and koa(v2) apps.
const router = new LarkRouter();
router.get('/foo/bar', (req, res) => res.end("/foo/bra requested!"));
router.on('error', (error, req, res) => {
res.statusCode = 500;
res.end(error.message);
});
http.createServer(router.routes()).listen(3000);
const router = new LarkRouter();
const app = new Koa();
router.get('/foo/bar', async (ctx, next) => {
ctx.body = '/foo/bar requested!';
await next();
});
router.on('error', (error, ctx, next) => {
ctx.statusCode = 500;
ctx.body = error.message;
return next();
});
app.use(router.routes()).listen(3000);
See path-to-regexp
. Params object is bind to the first argument of the app processor.
router.get('/:foo/:bar', (ctx, next) => { console.log(ctx.params); }); // ===> { foo: xxx, bar: xxx }
router.get(/^\/(\d+)\/(\w+)$/, (ctx, next) => { console.log(ctx.params); }); // ===> { 0: xxx, 1: xxx}
Lark router has 3 special methods.
router.all('/foo/bar', handler); // ===> response to GET/POST/DELETE/... /foo/bar
router.other('*', response404notfound); // ===> response to GET/POST/DELETE/... /foo/bar if no other route matched
router.routed('/foo/bar', () => console.log('/foo/bar has been routed')); // ===> response to GET/POST/DELETE/... /foo/bar if some routes matched
You could nest routers together:
mainRouter.all('/api', apiRouter);
For async processors, return promises.
router.get('/', () => new Promise(...));
router.get('/foo', async () => { ... });
FAQs
An koa route initialization and configuration module.
The npm package lark-router receives a total of 12 weekly downloads. As such, lark-router popularity was classified as not popular.
We found that lark-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.