A lot of people were using a convenient little application called InsomniaX to disable temporarily the sleep feature on MacOS that is activated due to inactivity after a few minutes or when you close your laptop's lid (screen).
However, a security vulnerability was identified in the software and after that point in time it is considered a legacy software as it is no longer actively being developed.
There are alternatives depending on what you want to do. The easiest way to keep the mac from going to sleep is to use a terminal window with the built-in command: caffeinate
However, this does not help when you change focus from that particular terminal window or need to temporarily close your laptop's lid without going into sleep mode.