How to generate unique ID with node.js

前端 未结 14 1860
感动是毒
感动是毒 2020-12-12 10:17
function generate(count) {
    var founded = false,
        _sym = \'abcdefghijklmnopqrstuvwxyz1234567890\',
        str = \'\';
    while(!founded) {
        for(va         


        
14条回答
  •  抹茶落季
    2020-12-12 11:03

    to install uuid

    npm install --save uuid
    

    uuid is updated and the old import

    const uuid= require('uuid/v4');
    

    is not working and we should now use this import

    const {v4:uuid} = require('uuid');
    

    and for using it use as a funciton like this

    const  createdPlace = {
        id: uuid(),
        title,
        description,
        location:coordinates,
        address,
        creator
      };
    

提交回复
热议问题