How to generate short id in Node.js ?
In this article we are going to see how to generate a short id in Node.js. There is an NPM package called ‘shortid’ used to create short non-sequential url-friendly unique ids. By default, it uses 7-14 url-friendly characters: A-Z, a-z, 0-9, _-. It Supports cluster (automatically), custom seeds, custom alphabet. It Can generate any number of ids without duplication.
Setting up of the environment:
Setting up of the NPM package of the project :
npm init -y
Installing Dependencies :
npm install express shortid
Basic Express server:
Example: Importing ‘shortid’ into our project, there are lots of features in shortid module.
const short = require('shortid');