added a readme
[nodejsws.git] / Readme.md
1 NJSPURLS
2 ========
3
4 Stands for "Node JS, Primary URL Servicer". It is a simple web framework that provides
5 and overhead for createing web applications based on the basic URL. There are manu
6 default parts that are used when servicing a web based applications.
7
8 How It Works
9 ============
10
11 In NodeJS you define a layout using NJS script (html with tags that define purls that
12 are called to render pages). For EG if i wanted to create a page "http://host/mypage"
13 then i create a file called ./purls/mypage.js and inside this file i might create the
14 following:
15
16 exports.layout = function(request, response) {
17         var layout = "<html><head><title><?njs title ?></title><body><?njs body ?></body></html>";
18         
19         return layout;
20 }
21
22 exports.title = function(request, response, callback) {
23         response.write("i am a title");
24         callback();
25 }
26
27 exports.body = function(request, response, callback) {
28         response.write("i am a body");
29         callback();
30 }
31
32 A request to http://localhost:8888/mypage will create html that looks like so:
33
34 <html><head><title>i am a title</title></head><body>i am a body</body></html>
35
36 and it does this by printing out the layout then reaplcing the <?njs ... ?> bits 
37 with the functions in the purl defined with the same name of the tag. For EG
38 <?njs body ?> means call the exported function "body" from mypage.js. Defaults
39 also do exist, and so you dont necessarily have to define your own everytime.