The easiest way to send a message via XMPP to Node
There is probably no other simpler XMPP client library for Node than node-simple-xmpp . In this case, the minimum Node.js script to send a message to another Jabber user:
var xmpp = require('simple-xmpp'); var jid = ' testjs@xmpp.jp '; var pwd = 'xyz'; var server = 'xmpp.jp'; var port = 5222; xmpp.on('online', function(data) { console.log('Connected with JID: ' + data.jid.user); xmpp.send(' testjs@007jabber.com ', 'hello! time is '+new Date(), false); }); xmpp.on('error', function(err) { console.error("error:", JSON.stringify(err)); }); xmpp.connect({ jid: jid, password: pwd, host: server, port: port });
If both accounts have never talked together, a preliminary "subscription" is required:
xmpp.subscribe(' testjs@007jabber.com ');
As you can see in package.json, node-simple-xmpp lib has a dependency on [node -xmpp-client] ( https://github.com/xmppjs/xmpp.js/tree/node-xmpp/packages/node-xmpp -client ).
Use with Google Talk / Hangouts
The above script works (tested) also with Google Talk / Hangouts, you just need to replace xmpp.jp server with talk.google.com and use a Google account. Turn on https://myaccount.google.com/lesssecureapps to enable the Node.js script to sign in to your Google Account.
Other XMPP libraries
Compared to https://npms.io/search?q=node-xmpp, there are several other XMPP client libraries for Node, however, almost all of them depend on node -xmpp-client or a limited BOSH connection (HTTP poll).
One interesting lib for those used for client side Strophe.js seems to be node-strophe . It is based on Strophe.js release 1.0.2, which is a library for applications running in any browser. Unfortunately, this version was not supported except for BOSH (see Strophe.js changelog ), websocket is available only from version 1.1.0.
Exploring alternatives without specific XMPP libraries
An alternative solution without specific XMPP libraries may use Net module , but in this case you need to manage all XMPP interactions to establish a connection to the server, see https://wiki.xmpp.org/web/Programming_XMPP_Clients .
The following is a very crude example script trying to initiate a connection to a Jabber server using the Net module:
var net = require('net'); var jid = ' testjs@xmpp.jp '; var pwd = 'xyz'; var server = 'xmpp.jp'; var port = 5222; var msg = '<stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" to="'+server+'">'; var client = new net.Socket(); client.connect(port, server, function() { console.log('Connected'); client.write(msg); }); client.on('data', function(data) { console.log('Received: ' + data); });
You can see the correct answer from the Jabber server in the console log, but from this point on there is a mess: you must start TLS messaging (see <a9> )
conclusions
I think the only possible alternative is the first one using the node-simp-xmpp library.