In this article, we review generate-nano-id.ts file. You will learn:
What is Nano ID?
How generateNanoId function is used?
What is Nano ID?
Nano ID is a tiny, secure, URL-friendly, unique string ID generator for JavaScript.
Features
Small. 118 bytes (minified and brotlied). No dependencies. Size Limit controls the size.
Fast. 50% faster than native crypto.randomUUID().
Safe. It uses hardware random generator. Can be used in clusters.
Short IDs. It uses a larger alphabet than UUID (A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.
Portable. Nano ID was ported to over 20 programming languages..
Nano ID is built by Evil Martians, an American design and engineering consultancy for developer tools, AI, and cybersecurity startups.
How generateNanoId function is used?
In the n8n, when you click on Create workflow, you will get url that looks something like this — /workflow/V1StGXR8_Z5jdHi6B-myT.
Here the id is generated using generateNanoId, but this happens inside the beforeEnter method in the editor-ui/router.ts.
beforeEnter: (to) => {
// Generate a unique workflow ID using 16-character nanoid and redirect to it
// Preserve existing query params (e.g., templateId, projectId) and add new=true
const newWorkflowId = generateNanoId();
return {
name: VIEWS.WORKFLOW,
params: { workflowId: newWorkflowId },
query: { ...to.query, new: 'true' },
};
},
},
Technically when you click on Create workflow button in the workflows route, the code indicates that it redirects to /workflow/new but because of this check — beforeEnter, nanoId replaces the new with an actual nano id.
About me:
Hey, my name is Ramu Narasinga. Email: ramu.narasinga@gmail.com
I spent 3+ years studying OSS codebases and wrote 400+ articles on what makes the production-grade. Now I'm putting that into practice differently - instead of writing every fix myself, I run coding agents that do it.
How it works? Register your machine as a Runtime, point it at your repo. Agents pick up issues. write the fix, open the PR. You just review, they execute.
Build your coding agents and get more work done in less time at thinkthroo.com

Top comments (0)