Join multi-user chat with node-xmpp-client

XEP-0045 defines the XMPP protocol extensions required to join multi-user chat rooms, and receive and post messages. In this post I use the execllent node-xmpp-client library to join a multi-user char room. Any messages sent to the chat room after you join are received, but I don’t parse them in the code below.

node-xmpp-client can be installed from source or npm as follows

npm i -g node-xmpp-client
export NODE_PATH=/usr/local/lib/node_modules

Change NODE_PATH value appropriately. npm -g list should show where your global node_modules folder is located.

Here’s the code that creates a new XMPP client, and sends a presence stanza to the XMPP server to join a chat room.

var Client = require('node-xmpp-client')

var jid = 'user@domain'
var password = 'password'
var room = 'room@domain/nickname'

var client = new Client({
    jid: jid,
    password: password,
    preferred: 'PLAIN'

client.on('online', function() {
    var stanza = new Client.Stanza('presence', {from: jid, to: room})

client.on('stanza', function(stanza) {
    console.log('Incoming stanza: ', stanza.toString())

client.on('error', function(e) {

process.on('SIGINT', function(code) {
    console.log('leaving the room')
    var stanza = new Client.Stanza('presence', {from: jid, to: room, type: 'unavailable'})

    setTimeout(function() {
    }, 1000);

If you don’t specify a unique nickname, the XMPP server will likely reject the request to join the room. Modify the above script appropriately, and invoke node to execute it.

If you get any strange errors, try setting the DEBUG environment variable as follows, and try again.

export DEBUG=*


WeightLE (\ˈwāt-lē\) is a concept Bluetooth Smart utility, not unlike a beverage coaster or beermat, that learns from the weight placed over it, and notifies you when it’s too low. You get to decide what low means.


It can be used with bottles, cups, jars, and even water coolers. Anything that isn’t smart yet can be made smarter, so you are not left without that something when you need it the most. An accompanying Smartphone or Smartwatch app is required with WeightLE.