A laptop used as a small server at home, or one chewing through a long export, shouldn’t doze off just because the screen went dark.
System Settings > Battery > Options
Prevent automatic sleeping on power adapter
when the display is off: on
With this on, the Mac stays awake while it is on the charger, even though the display switches off by its own timer. On battery nothing changes, which is what I want: a laptop in a bag should be asleep.
This is the permanent version. If you only need it for one command or one afternoon, the caffeinate command does that without touching settings.
I would use it for a machine that mostly sits on a desk with the charger in: file sharing for the household, a backup that runs overnight, remote access from another room.
It costs electricity, and Apple says as much about settings that keep a Mac from sleeping. It also does not cover the lid. Close a laptop without an external display set up and it still goes to sleep. And give it air: a Mac working all night on a duvet or in a closed drawer gets warm for no good reason.
Further reading: Change Battery settings on a Mac laptop