Prevent a system running macOS from going to sleep. Picks the preferred method (pmset
/caffeinate
) depending on system version.
const vaka = require(`vaka`)
// Prevent sleep indefinitely
vaka()
.then(console.log.bind(null, `caffeinate/pmset pid:`))
.catch(console.log)
// Prevent sleep until process exits
vaka({ pid: process.pid })
.then(console.log.bind(null, `caffeinate/pmset pid:`))
.catch(console.log)
// Prevent sleep for 10 seconds
vaka({ timeout: 10 })
.then(console.log.bind(null, `caffeinate/pmset pid:`))
.catch(console.log)
Returns a Promise which resolves to the pid belonging to the underlying pmset
or caffeinate
instance.