The stat module can be used to check if a directory exists by specifying the path parameter and registering the result. If the registered result contains a stat.isdir value that is defined and true, then the directory exists and a debug message can confirm this. The stat module retrieves file or file system status and has a mandatory path parameter to check.