express-mongodb-rest-api-boilerplate
node-redlock
express-mongodb-rest-api-boilerplate | node-redlock | |
---|---|---|
13 | 2 | |
593 | 1,734 | |
- | - | |
4.4 | 3.7 | |
10 months ago | 3 months ago | |
TypeScript | TypeScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
express-mongodb-rest-api-boilerplate
node-redlock
-
Build an Idempotent API in Node.js with Redis
async function create(req, res) { let lock; try { // Try to acquire the lock lock = await service.urlService.acquireLock( "URL:CREATE:ExclusiveLock", 100 ); const { longURL } = req.body; // Check if the mapping already exists const mapping = await service.urlService.findByLongURL(longURL); if (mapping) { return res.status(HTTP_STATUS_CODES.SUCCESS).json({ status: true, message: "Short slug created successfully", data: { slug: mapping.slug }, }); } // New long URL, generate a new and unique slug const slug = service.urlService.generateNewSlug(); // save short URL <> long URL mapping to the database await service.urlService.saveToDB(slug, longURL); // Return the newly generated short slug return res.status(HTTP_STATUS_CODES.SUCCESS).json({ status: true, message: "Short slug created successfully", data: { slug }, }); } catch (err) { return res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).json({ status: false, message: "Could not create short slug", error: err, }); } finally { /** * Manually release the lock when the operation is complete * * NOTE: Redlock's release method is not a no-op, it throws an error if you try to release an already expired lock ([more here](https://github.com/mike-marcacci/node-redlock/issues/168#issuecomment-1165700540)). Setting a small TTL usually triggers this unexpected behavior. * As a workaround, we're ignoring the errors from lock.release() */ if (lock) await lock.release().catch(() => {}); } }
-
Advanced caching mechanisms using distributed locks and async pub/sub systems.
Example: The following example uses Node.js npm module Redlock, which implements Redlock. Redlock is available as a package in many languages.
What are some alternatives?
auth-backend - Typescript RESTful backend application template for User Authentication and Authorization. 🔒🔑📨
Conveyor MQ - A fast, robust and extensible distributed task/job queue for Node.js, powered by Redis.
auth - 🔐 Refresh/Access Token Authentication Demo with Client Side Rendering, Server Side Rendering and Websockets
sidewinder - Type Safe Micro Services for Node
json-server-auth - Authentication & Authorization flow for JSON Server
Basic-Node-JWT-auth
docker-express-postgres-boilerplate - :zap: A simple boilerplate with Docker, Express, PostgreSQL and authentication
Amazone_clone_Flutter_NodeJs - a Full Stack Amazon Clone with Admin Panel using Flutter, Riverpod,Node, MongoDB,
react-hooks-uikit-express-oauth-boiler-v2 - A React/TypeScript fullstack boilerplate utilizing React hooks, using Express as backend, UIKit for frontend, MongoDB for storage & open-authenticator for OAuth.
remote-resistance - Play Resistance with your friends anywhere – a real-time remote version of the game. Visit resistance.quest
Orbital Sync - Synchronize multiple Pi-hole instances
express-ts-auth-service - A ready-to-use authentication service build with express.js, that provides secure and reliable authentication using JSON Web Tokens (JWT) and refresh token rotation