Node.js · Senior · Question 54 of 75

What does the using declaration (explicit resource management) give Node.js code?

{
  await using conn = await pool.connect();
  await conn.query("...");
} // conn is disposed here

Explanation

It replaces many try/finally blocks. Some Node.js APIs, like timers and file handles, already implement the dispose symbols.

Further reading

Problem with a question

Node.js · Senior · question 54

Test yourself

Take the Node.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz