2017-10-04 113 views
-4

我想爲保險合同生成唯一的ID,不知道使用哪個工具...在Node.js中生成唯一標識符的最好方法是什麼?

+0

Google上的簡短搜索會給你一些答案 –

+0

不幸的是,google返回此頁面https://www.google.ch/search?q=What+is+the+best+way+of+generating+unique+ id%27s + in + Node.js%3F&oq = What + is + the + best + way + of + + unique + id%27s + in + Node.js – syzer

+0

Google search:https://www.google.ch/search?q = unique + id + node + js – tbking

回答

1

有幾種選擇來創建獨特的ID。最簡單的只是一個遞增的整數。但是,我認爲你會有某種形式的api,並且你可能不希望其他人能夠猜測其他人的唯一id。所以,我會去uuid.v4(https://www.npmjs.com/package/uuid

在你的代碼

const uuidv4 = require('uuid/v4') 
const uniqueInsuranceId = uuidv4() 

希望我能幫助安裝包

$ yarn add uuid 
$ npm install uuid --save 

然後。

1

你應該使用uuid包。

特點:

支持版本1,4和5點的UUID

跨平臺

採用加密強的隨機數的API(可用時)

零依賴,佔地面積小(...但不是這個小)

You can download from here

+0

評論會非常完美 –

+0

我喜歡你的回答。這對我幫助很大。但我不能投票它:(。 – syzer

相關問題