Servarunited is an HTTP web-server written in node.js using sockets.
npm install servarunited
var server = require('servarunited');
- 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 : {} }
-
-
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);
-
MIT
Open Source matters!