I have read some documentation on async/await and tried coming with an example to understand it better. What I was expecting is that the below code without async and await would print first the string 'Completed', followed by the content of the file. But even after adding async and await, I see that the printing order is unaffected. My impression was async and await usage in this case would print the file contents first followed by the string 'Completed'.
var fs = require('fs');
getTcUserIdFromEmail();
async function getTcUserIdFromEmail( tcUserEmail ) {
let userInfo = {};
let userFound = false;
// Read the file that is containing the information about the active users in Teamcenter.
await fs.readFile('tc_user_list.txt', function(err, data) {
if( err )
console.log( err );
else
console.log( data.toString() );
});
console.log( 'Completed method');
}
Request you to point out what I am doing wrong.
Thanks, Pavan.