When it is set to true it doesn’t use the cache on the UUID generation. The method takes an options object that can have a disableEntrop圜ache boolean value that defaults to values. It also provides a method called randomUUID to generate UUID in Node.js without instaling any new NPM module. It provides cryptographic functionally for multiple methods and algorithms like OpenSSL’s hash, HMAC, cipher. The crypto module was added from Node.js 14.17.0. There are of course a lot of other NPM packages that can perform that task but we will see code examples of the 2 most popular options. We will discuss one native way to do it and two NPM packages that can do it. There are multiple ways to generate at UUID in Node.js. In the consequent part, you will learn 3 methods to generate a UUD in Node.js regardless of any framework you use. Using nodemon with these code examples will help too. If you are interested in doing other things with Node.js, please do browse reading file line by line with Node.js. If you want to read more about UUID feel free to read the wiki page which explains UUID4 too. Hide your autoincrement ID #īaseline, whenever you need to hide your autoincerment ID it is best to use a random number or pattern that is hard if not impossible to guess. The same example can be applied for customer ID or shipment ID or any other integer identifier that increments by 1. That is why exposing auto-increment IDs is bad. Just with the order id which is an autoincrement integer your competitor, possibly unknowingly is giving out a vital business metric to anyone who can do some due diligence. Averaging at 367.66 orders per day, you can easily do the math for each week. You can quickly do the math that your competitor has (111050-100020) 11030 orders in 30 days. If the order ID on the first day of the month is 100020 and the order ID on the last day of the month is 111050. Now to know the order volume of your competitor all you need to do is order on the first day of the month and the last day of the month. You have found out that the order ID used by your competitor is an autoincrement integer primary key. Get your competitor’s order volume example #įor example, you have an e-commerce website and you have a fierce competitor. There are other great usages of UUID but hiding the autoincrement ID stands out in my opinion. A sequential auto-increment ID can reveal much more than you intended. They can also be used to act as a hash which can be decoded back to an integer or other identifier. UUID is a great way to hide sequential database IDs. Given we have that mentioned, in the next section we will look into why and when to use a UUID.
0 Comments
Leave a Reply. |