首先执行:npm install node-uuid -g
JavaScript代码
- var uuid = require('node-uuid');
- //var uuid = require('/usr/local/nodejs/lib/node_modules/node-uuid');
- console.log(uuid.v1())
- console.log(uuid.v4())
注明:如果在linux下编译安装node可以使用软连接ls 或这直接写绝对路径引入需要的nmp模块!
v1 是基于时间戳生成uuid
v4是随机生成uuid
结果:
- 57af5b10-3a76-11e5-922a-75f42afeee38
- f3917fb9-9bde-4ec1-a7cf-966251b3d22a