controllers/new.js
// then when code is unique we return the value
then when code is unique we return the value
then when code is unique we return the value
function generateNewCode(){
  let newShort = generate();
  read.shortcode(newShort, function checkShortcodeExistsDuringGeneration(err,docs){
    if(docs.length){
      generateNewCode();
    }
  });
  return newShort;
}
function generateNewCode ( ) { let newShort = generate ( ) ; read . shortcode ( newShort , function checkShortcodeExistsDuringGeneration ( err , docs ) { if ( docs . length ) { generateNewCode ( ) ; } } ) ; return newShort ; }
then when code is unique we return the value
then when code is unique we return the value