36

I'm running a long running custom nodejs script and would like to be notified when the script is completed.

How do I make nodejs trigger the "System Bell"?

DebugXYZ
  • 905
  • 1
  • 10
  • 17

3 Answers3

67

Output the BELL character (Unicode 0007) to the standard output.

console.log('\u0007');

Update 2023

Solution above doesn't work anymore, but writing directly to stdout still works (tested on Node.js v14.20):

process.stdout.write('\u0007');

References

dbf
  • 3,278
  • 1
  • 24
  • 34
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
14

The console.log('\u0007') didn't work for me running VSCode on windows 10. The following code did work:

import { exec } from 'child_process'
exec(`rundll32 user32.dll,MessageBeep`)
Ronen
  • 1,225
  • 13
  • 10
  • even if the `console.log` version worked for me, it did not work after building an electron app with the code. Your solution also works for electron apps on windows 10. – messerbill Dec 07 '20 at 20:13
  • one more case, use `>` redirect console output to a file – benbai123 Jul 01 '21 at 12:30
2

I know this question is tagged unix, but I found it from Google so here is a Windows PowerShell solution.

The current answer works fine in Windows, but I wanted something a bit more unique than the standard Windows tone so this worked better for my needs:

const { exec } = require('child_process');

// Single beep
exec("[console]::beep(1000, 500)", {'shell':'powershell.exe'});

// Multiple beeps
exec("1..3 | %{ [console]::beep(1000, 500) }", {'shell':'powershell.exe'});
Sherwin F
  • 658
  • 7
  • 13