Skip to content

13 如何生成唯一ID

孙正华 edited this page Jul 26, 2018 · 1 revision

可以使用 node-uuidshortid 等生成一个唯一标识。
以 shortid 为例:
安装

$ npm install --save shortid

使用

const shortid = require('shortid');
//输出 4kyTq04Ae
console.log(shortid.generate());

iBlog2 中的代码:

https://github.com/eshengsky/iBlog2/blob/master/routes/admin.js#L215

shortid.generate()