Question: I have this simple code:

```
(async ()=>{
    const five = await printHello()
    console.log(`five: ${five}`);
})()

async function printHello(){
    console.log('Hello World')
    return 5;
}

console.log("App started");

```

My expectation is that it should print :

```
App started    
Hello World
five: 5

```

As the anonymous function that gets executed is marked async.

However it prints, even after multiple trials :

```
Hello World
App started
five: 5

```

Can some one please explain me why this is happening ?

Answer: 
Your code is not doing anything asynchronous. The `printHello` method executes synchronously.
Prefixing a function with `async` just make sure that it returns a Promise. You could replace it with callback and it will work the same way, as callback will return immediately without waiting for the next tick of the event loop.

So if you want your code to behave the way you want it to, then you will have to wrap it around with a setTimeout or setImmediate call.

```
async function printHello() {
      setImmediate(() => {
        console.log('Hello World');
        return 5;
      });
  }

```
All guys have given plenty helpful answer, but I will need to write an answer for this to help people who come up with a similar mentality as me : Just by marking a function async [or wrapping it in Promise] will not make your CPU intensive code to run as asynchronous fuct in nodejs.

My understanding prior to this problem, was that we can just put async before a function and put all heavy task on it. Aysnc will some how let nodejs event loop know once its finished [returned]. And I use to think it does this all things under the hood via spawning threads.

But this understanding is incorrect. Node is single threaded, if you ever going to write your code. Do never ever put any thing heavy task on nodejs.

Consider this express app:

```
const express = require('express')

const app = express()

app.use('/name/:name',(req,res)=>{
    if(req.params['name']==='John'){
        res.end(timeConsumingFunct(2000).toString())
    }else{
        res.end(timeConsumingFunct(10000).toString())
    }
})

function timeConsumingFunct(ms) {//simulating CPU intensive work
    var start = Date.now(),
        now = start;
    while (now - start < ms) {
      now = Date.now();
    }
    return ms/1000;
}

app.listen(3000,()=>{
    console.log('Server started at : http://localhost:3000')
})

```

Now if you access : `http://localhost:3000/name/Tom` first and then `http://localhost:3000/name/John` in your browser, Mr.John will need to wait for total of 12 seconds minimum.
These is because Node js is single threaded no matter you use async or a Promise to wrap your `timeConsumingFunct` it will hung up entire flow.

The only way to make it truly async will be to use child process or worker api or write it in C++ .

Whatever you write as a JS is always synchronous and its going to hang up all the requests, know that before you think you can make any thing aysnc in nodejs.