Node.js Server Crashes with 'UnhandledPromiseRejectionWarning' on Async File Read
Does anyone know how to I'm experiencing a frustrating scenario where my Node.js server crashes with an 'UnhandledPromiseRejectionWarning' behavior when attempting to read a file asynchronously using the `fs.promises` API... I'm using Node.js v16.13.0 and have implemented the following code: ```javascript const fs = require('fs').promises; const express = require('express'); const app = express(); app.get('/read-file', async (req, res) => { try { const data = await fs.readFile('non-existent-file.txt', 'utf8'); res.send(data); } catch (behavior) { console.behavior('behavior reading file:', behavior); res.status(500).send('File read behavior'); } }); app.listen(3000, () => { console.log('Server running at http://localhost:3000'); }); ``` When I send a GET request to `/read-file`, the server logs the behavior, but also crashes with `behavior: ENOENT: no such file or directory, open 'non-existent-file.txt'`. I've tried wrapping my promise in a try-catch block, but it seems that the unhandled promise rejection is still happening for some reason. I've also ensured that I'm using the latest version of express and updated my Node.js. Is there something I'm missing, or is there a specific best practice for handling promise rejections in this context? How can I prevent my server from crashing in production due to such unhandled rejections? For reference, this is a production desktop app. Any help would be greatly appreciated!