why value is undefined in node which is returned by database : <p>I am learning nedb and Node.js</p>

<p>Here is the database.js file:</p>

<pre><code>// Initialize the database
var Datastore = require('nedb');
db = new Datastore({ filename: 'db/persons.db', autoload: true });

//Returns a specific Person
exports.getPerson = function(id){

  //Get the selected person details from the database
  db.findOne({ _id: id }, function(err, doc){

    console.log(doc);

    //Execute the parameter function
    return doc;

  });
}
</code></pre>

<p>Now in my main.js file I am calling the getPerson function as follows:</p>

<pre><code>//Get person from the database
var person = database.getPerson(id);

console.log(id);
console.log(person);

document.getElementById('firstname').value = person.firstname;
document.getElementById('lastname').value = person.lastname;
</code></pre>

<p>In the output window of chrome browser:</p>

<p><a href="https://i.stack.imgur.com/QAz2Y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QAz2Y.jpg" alt="enter image description here"></a></p>
