Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
System Beep in Node.js
function alertTerminal(){
console.log("\007");
}
@shovon

This comment has been minimized.

Copy link

commented Feb 7, 2013

This is what I've been looking for. Thanks!

@shovon

This comment has been minimized.

Copy link

commented Feb 7, 2013

If you are a pedant like me, and you want to prevent a new-line character from displaying onto the console, then you can use,

process.stderr.on("\007");

Instead of console.log.

@danielchatfield

This comment has been minimized.

Copy link

commented Aug 14, 2013

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

@marlonbernardes

This comment has been minimized.

Copy link

commented Mar 8, 2014

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

@benlipp

This comment has been minimized.

Copy link

commented Jan 18, 2015

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

@Emuentes

This comment has been minimized.

@jayralencar

This comment has been minimized.

Copy link

commented Nov 30, 2015

@darylteo

This comment has been minimized.

Copy link

commented Feb 1, 2017

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

@aneilbaboo

This comment has been minimized.

Copy link

commented Jul 16, 2018

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

This comment has been minimized.

Copy link

commented Jul 22, 2018

@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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.