Search code examples
node.jswindows-10sleep-mode

Entering Windows 10 sleep mode programmatically with Node.js


I want to be able to programmatically make my Windows 10 computer enter sleep mode using Node.js.

What can I write to achieve this?


Solution

  • const {exec} = require('child_process');
    exec("rundll32.exe powrprof.dll, SetSuspendState Sleep"); 
    

    The require statement lets you use a Node.js module that can execute native Windows commands. This module comes bundled with Node.js so you don't need to install it.