0.0.2 • Published 8 years ago
serverunited v0.0.2
Serverunited
Serverunited is an HTTP web-server written in node.js using sockets.
Installation
npm install serverunited
var server = require('serverunited');
How to set-up:
- To start the server, use server.startServer(port, address)
server.startServer(8080, '127.0.0.1');
Routing mechanism
For adding a route, use server.addRoute(method, path, function)
server.addRoute('get', '/', home);
- method corresponds to the HTTP method (get or post)
- path is the requested path by the browser
- function is the user-defined function
addRoute(method, path, function) binds the function to a set of method and path
function addRoute(method, path, func) { ROUTES[method][path] = func; }
ROUTES is an object used to build method-path pair
var ROUTES = { get : {}, post : {} }
How to use:
To send the HTML data, use server.sendHTML(request, response, requested_HTML)
server.sendHTML(request, response, content);
To send the JSON data, use server.sendJSON(request, response, JSON_content)
server.sendJSON(request, response, content);
To handle sessions, use:
To add session
server.addSession(request, content);
To get session
server.getSession(request);
To delete session
server.deleteSession(request);
License
MIT
Open Source matters!