moving api require inside db callback