Task 3.2.

Docusaurus is an open source application for building, deploying, and maintaining open source websites. You can see a code fragment from the start-server.js file, responsible for starting the Docusaurus web server. The code fragment is trying to determine whether some selected port on the machine is free and can be bound to.

Line 1 calls the check() function to determine the availability of the hostname and port. check() returns a promise which we will refer to as p. At line 1, the program registers an anonymous function as the fulfill reaction for p. The anonymous function is executed when p is fulfilled, i.e., the availability of selected hostname and port is checked. If the address is in use, the program prints a descriptive error message and exits, unable to start the server (lines 3&4). If the address is available, the program prints a message to the console, declaring that it is starting the server (line 6). It then instantiates a server object and starts the server locally on the specified port (lines 8&9). The anonymous fulfill reaction ends at line 11 with a running server.

Executing this file, the user initially observes the two printed messages regarding availability of the server's address and then starting it. However, some users have reported an issue that in some cases the server prints that the server is starting, but it doesn't start and nothing happens after that.

How can the code be updated to address that issue? *

* You can either provide some code fragment and a line number as where is should be located, or just describe what the fix should look like.

      
tcpPortUsed.check(port, 'localhost')Promise has no reaction to handle rejections (exceptions)!
    .thenPromise has no reaction to handle rejections (exceptions)!(function(inUse) {
	if (inUse) {
		console.error(port + ' is in use');
		process.exit(1);
	} else {
		console.log('Starting Docusaurus server on port ' + port + '...');
		// start local server on specified port
		var server = require('./server/server.js');
		server(port);
	}
});