Let's break it down simply
Node.js uses asynchronous APIs so the event loop doesn't get blocked while waiting on I/O operations. An async function returns a Promise, and await just pauses that function until the Promise settles. You can run independent requests at the same time with Promise.all.
javascript
import { readFile } from 'node:fs/promises'
async function loadConfig() {
try {
const [app, messages] = await Promise.all([
readFile('./app.json', 'utf8'),
readFile('./messages.json', 'utf8')
])
return { app: JSON.parse(app), messages: JSON.parse(messages) }
} catch (error) {
throw new Error('Could not load configuration', { cause: error })
}
}
const config = await loadConfig()
console.log(config.app.name)You should see
Tutorial APITry It Yourself
Read two JSON files both sequentially and with Promise.all, then compare the execution time.
Discover Promises in Node.js — Node.js