-
Notifications
You must be signed in to change notification settings - Fork 5
Explore the sample server
Now let's take a look at ./node_modules/nodebotui/demoserver.js
var app = require('http').createServer(),
ui = require('nodebotui.js').listen(app);
app.listen(3000);
console.log("Server running at\n => http://localhost:3000\nCTRL + C to shutdown");
Yep, that's the whole enchilada. Let's look at the important lines:
####Create an HTTP Server
var app = require('http').createServer(),
We need an http server and this is the easiest way to get one. It doesn't serve up much, but you are welcome to wire this up with Express, Director, etc. NodebotUI doesn't really care, as long as the http.Server object is exposed so it can be passed to NodebotUI.
####Bind NodebotUI to the http Server
ui = require('nodebotui').listen(app);
Here we are requiring the NodebotUI module and calling the only export, "listen". NodebotUI attaches itself to the server like a remora and listens for requests that it is responsible for.
####Tell the HTTP Server to listen
app.listen(3000);
Here we invoke the Server.listen passing in a port number.
And that's all there is to it. All the client side code, sockets, server side johnny-five stuff, etc is handled for you. To start with your own project copy the demoserver.js file to your project root and start writing your HTML.
####Check out the full Documentation