docs.nestjs.com
                                
                                 docs.nestjs.com copied to clipboard
                                
                                    docs.nestjs.com copied to clipboard
                            
                            
                            
                        Avoiding EADDRINUSE with HMR
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
When using the default HMR example EADDRINUSE errors can occur, likely because close() is not awaited.
Maybe the example should look something like this instead:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
    if (module.hot?.data?.closePromise) {
        await module.hot.data.closePromise;
        module.hot.data.closePromise = null;
    }
    const app = await NestFactory.create(AppModule, {
        forceCloseConnections: !!module.hot,
    });
    if (module.hot) {
        module.hot.accept();
        module.hot.dispose((data) => data.closePromise = app.close());
    }
    await app.listen(3000);
}
bootstrap();
Minimum reproduction code
https://docs.nestjs.com/recipes/hot-reload
In which operating systems have you tested?
- [ ] macOS
- [ ] Windows
- [x] Linux
would you like to open a PR at https://github.com/nestjs/docs.nestjs.com

Thanks for the pointer. I'll do so once I'm reasonably sure that this fixed the sporadic EADDRINUSE I've been getting.