Talking to our bot from the browser
So now you've learned about XMPP connections and XMPP-FTW, and you have played with a JSON-based XMPP interface in a browser. Now let's build a very simple chat client to talk to the bot we wrote in Chapter 3, Building a One on One Chat Bot - The "Hello World" of XMPP.
Building a WebSocket-enabled web server in Node.js
First, let's create a new folder and initialize a new NPM project:
mkdir browser-chat && cd browser-chat npm init
Answer the questions however you wish (you can just happily accept all the defaults if you want). Once completed, you'll have a saved package.json
file that describes the project. As we install modules, we'll write their details into the file so that the installations can be repeated by others later.
Rather than use express, we're going to use the base HTTP module from Node.js, as we're only looking to deliver a couple of static assets from the server itself. Create a file called index.js
using an editor of your choice and...