Get username from uid

NodeBB Development
  • I'm writing a plugin that uses the hook
    I've got the plug-in logging the post data to the console fine.

    Im then trying to fetch the username from the uid from the post data.
    my basic library.js is:

    var User = module.parent.require('./user';);
    module.exports.emailalert = function(postData) {
    console.log(postData.uid); // this is returning '2'
    User.getUserField(postData.uid, 'username', function(data){
    console.log(data); // this is returning 'null'

    however User.getUserField is returning null.
    User module is definitely getting called.

  • Hey @cadack! That method is error-first, so give this a shot:

    User.getUserField(postData.uid, 'username', function(err, username) {

    You could also try the method User.getUsernamesByUids

  • @julian how did I miss that! Cheers buddy

Suggested Topics