Working with Node.js Driver using TypeScript and Express

I am working with the MongoDB Node.js Driver in Express and TypeScript. I am a beginner I must say and I am trying to wrap my head around how to work with the Node.js driver in Express and TypeScript without relying on an ORM. My database is hosted locally, I am not using MongoDB Atlas.
Here is the code that I am using to connect to the database:

export const connectToDatabase = async(client:MongoClient) => {
  try {
    await client.connect();
    console.log("CONNECTED TO THE DATABASE");
  } catch (err) {
    console.log("ERROR CONNECTING TO THE DATABASE")
    console.error(err);
  }
}

Then here is the code where I call the connectToDatabase() function to connect to the database and then listen for requests on port 3000 and also find a document in the database:

// execute express
const app = express();
const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri);
const dbName = "channel";
const collectionName = "subscribers"

async function main(client: MongoClient) {
  try {
    await connectToDatabase(client);
    app.listen(3000, () => {
      console.log('Listening on port 3000');
    });
    // The code below is what causes a behaviour I can't explain
    const result = await findData();
    console.log(result);
  
    
  } catch (err) {
    console.error(err);
  } finally {
    await client.close();
    console.log("Database Connection Closed");
  }
}

main(client);

//function to find data in the collection in the database
async function findData(){
  const result = await client.db(dbName).collection(collectionName).findOne();
  return result;
}

The code above, where after listening for requests on port 3000, I fetch a document from the subscribers collection, leads to the following output:

[build] 8:53:44 PM - Found 0 errors. Watching for file changes.
[run] [nodemon] starting `node dist/index.js`
[run] CONNECTED TO THE DATABASE
[run] Listening on port 3000
[run] {
[run]   _id: new ObjectId('658b0edb390bbbe1992c7b99'),
[run]   name: 'Ada Lovelace',
[run]   age: 23,
[run]   city: 'London',
[run]   country: 'United Kingdom'
[run] }
[run] Database Connection Closed

However, when I comment out the code that gets data from the collection after starting the server on port 3000, that is commenting out the following two lines:

const result = await findData();
console.log(result);

I get the following output:

9:04:26 PM - File change detected. Starting incremental compilation...
[build] 
[build] 
[build] 9:04:26 PM - Found 0 errors. Watching for file changes.
[run] [nodemon] restarting due to changes...
[run] [nodemon] starting `node dist/index.js`
[run] CONNECTED TO THE DATABASE
[run] Database Connection Closed
[run] Listening on port 3000

From my understanding, the finally block which closes the connection runs before app.listen(). What could be the cause of this? I’d like the server to listen first, and then later have the connection close later. How do you explain this behaviour of the finally block running before app.listen()? Is there something I am doing wrong?
Thank you for your time.