39

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

3
  • 4
    The same way as with anything else you run in a console window: output the BEL character (ASCII 7) to the standard output. Commented Dec 19, 2011 at 5:57
  • 6
    Exactly what Karl says: console.log('\u0007');
    – wulong
    Commented Dec 19, 2011 at 6:02
  • 1
    @wulong, That worked great, thanks! You should post this as an answer.
    – Brad
    Commented May 14, 2012 at 0:29

3 Answers 3

72

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

1
  • 7
    It works in terminal, but not in terminal inside vscode.
    – Codler
    Commented May 25, 2020 at 9:35
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`)
2
  • 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
    Commented Dec 7, 2020 at 20:13
  • one more case, use > redirect console output to a file
    – benbai123
    Commented Jul 1, 2021 at 12:30
3

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'});

Not the answer you're looking for? Browse other questions tagged or ask your own question.