Skip to content

Instantly share code, notes, and snippets.

@taterbase
Created July 21, 2012 05:01
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save taterbase/3154646 to your computer and use it in GitHub Desktop.
Save taterbase/3154646 to your computer and use it in GitHub Desktop.
System Beep in Node.js
function alertTerminal(){
console.log("\007");
}
@danielchatfield
Copy link

If you are using 'use strict' (which you should be) then use "\x07" instead of "\007"

@marlonbernardes
Copy link

Yet another option:
process.stdout.write('\x07');

@benlipp
Copy link

benlipp commented Jan 18, 2015

None of these work for me, but I guarantee that my speaker works. Tips?

@Emuentes
Copy link

@jayralencar
Copy link

@darylteo
Copy link

darylteo commented Feb 1, 2017

If anyone else comes by confused by process.stderr.on("\007"); it should be process.stderr.write("\007"); instead.

@aneilbaboo
Copy link

No sounds with any of the following on macOS High Sierra, node 8.10.0:

$ node --version
v8.10.0
$ node
> console.log('\x07')
> console.log('\007')
> console.log('\u0007')
> process.stderr.write('\x07')
> process.stderr.write('\007')
> process.stderr.write('\u0007')

node-beep seems to be built only for windows.

@aleclarson
Copy link

@aneilbaboo You need to unfocus the terminal tab/window and make sure the "Audible bell" setting is enabled
in Preferences > Advanced

$ node
> setTimeout(() => console.log('\x07'), 1250)
// Unfocus the terminal before the timeout expires.

@mayeaux
Copy link

mayeaux commented Jun 20, 2019

Thanks @aleclarson . I needed to unclick 'Silence bell' in my iTerm 2 profile under 'Notifications'

Copy link

ghost commented Nov 15, 2019

Is it possible to change the beep frequency and duration with nodejs? Some languages have something like: Beep(hertz, milli) (https://stackoverflow.com/questions/38883092/how-to-make-motherboard-beep-through-c-code)
Or
SoundBeep, Frequency, Duration
(AutoHotKey: https://www.autohotkey.com/docs/commands/SoundBeep.htm)

@EminQasimov
Copy link

in git bash terminal
echo -e "\a"

@mohemos
Copy link

mohemos commented Aug 22, 2021

@mayeaux Mine didn't work because I was running the code in VSCode terminal, after switching to main terminal it worked

@dazhbog
Copy link

dazhbog commented Jan 22, 2022

windows or wsl

require("child_process").exec("powershell.exe [console]::beep(500,600)");

Mac

require("child_process").exec("afplay /System/Library/Sounds/Glass.aiff");

@democ2s
Copy link

democ2s commented Feb 24, 2024

Yeah, for some reason in VScode terminal it doesn't sound, in main terminal it works. Thanks for the tip!

@StasNemy
Copy link

StasNemy commented Apr 5, 2024

windows or wsl

require("child_process").exec("powershell.exe [console]::beep(500,600)");

Mac

require("child_process").exec("afplay /System/Library/Sounds/Glass.aiff");

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment