With just one line of code we can prevent device from sleeping. It doesn’t matter if the device is plugged in or not.
If you want to prevent the device from sleeping only if the device is plugged in then use this code
This function only works inside event handlers. So you can’t just call it whenever you like to. For example:
Make sure you have also added Intel XDK Device plugin in your app.
If you press the power button in that case it will go to sleep.