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?
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.