Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated to work with node-0.1.11.

  • Loading branch information...
commit 83e592960862fed9c1d3a1cdb89362ac78aec121 1 parent 4cfab6c
authored
55  README.markdown
Source Rendered
@@ -13,10 +13,8 @@ the root, it will be put in place of hello world.
13 13
       res.simpleHtml(200, "Hello " + (match || "World") + "!");
14 14
     }
15 15
 
16  
-    function onLoad() {
17  
-    	server.get(new RegExp("^/(.*)$"), hello);
18  
-    	server.listen(8080);
19  
-    }
  16
+    server.get(new RegExp("^/(.*)$"), hello);
  17
+    server.listen(8080);
20 18
 
21 19
 ## RESTful Resources made easy
22 20
 
@@ -35,10 +33,8 @@ controller generator that makes building a simple in-memory data controller easy
35 33
     	node.debug(id, JSON.stringify(people[id]));
36 34
     }
37 35
 
38  
-    function onLoad() {
39  
-    	server.resource("people", server.resourceController("people", people), on_change);
40  
-    	server.listen(8080);
41  
-    }
  36
+    server.resource("people", server.resourceController("people", people), on_change);
  37
+    server.listen(8080);
42 38
 
43 39
 ## Backend for SproutCore Todos example application.
44 40
 
@@ -86,10 +82,9 @@ This is a node.js backend for the Todos example in the SproutCore documentation.
86 82
 
87 83
     // Serialize the data to the disk
88 84
     function save_data() {
89  
-      var file = new node.fs.File();
90  
-      file.open("tasks.db", "w");
91  
-      file.write(JSON.stringify(tasks));
92  
-      file.close();
  85
+      var fd = node.fs.open("tasks.db", node.O_WRONLY, 0666).wait();
  86
+      node.fs.write(fd, JSON.stringify(tasks)).wait();
  87
+      node.fs.close(fd).wait();
93 88
     }
94 89
 
95 90
     // Load the data from the disk
@@ -158,23 +153,19 @@ This is a node.js backend for the Todos example in the SproutCore documentation.
158 153
     	}
159 154
     };
160 155
 
161  
-    function onLoad() {
162  
-	
163  
-    	// Mount our controller as a RESTful resource
164  
-    	server.resource('tasks', tasksController);
165  
-	
166  
-    	// Load the datastore
167  
-    	puts("Loading data from file...");
168  
-    	load_data(function (success) {
169  
-    		// Kickoff the server
170  
-    		if (success) {
171  
-    			puts("Loaded");
172  
-    		} else {
173  
-    			puts("Error, creating empty tasks array");
174  
-    			save_data();
175  
-    		}
176  
-    		// And start the server when done
177  
-    		server.listen(4000);
178  
-    	});
179  
- 
180  
-    }
  156
+    // Mount our controller as a RESTful resource
  157
+    server.resource('tasks', tasksController);
  158
+
  159
+    // Load the datastore
  160
+    puts("Loading data from file...");
  161
+    load_data(function (success) {
  162
+    	// Kickoff the server
  163
+    	if (success) {
  164
+    		puts("Loaded");
  165
+    	} else {
  166
+    		puts("Error, creating empty tasks array");
  167
+    		save_data();
  168
+    	}
  169
+    	// And start the server when done
  170
+    	server.listen(4000);
  171
+    });
6  hello_world.js
@@ -4,7 +4,5 @@ function hello(req, res, match) {
4 4
   res.simpleHtml(200, "Hello " + (match || "World") + "!");
5 5
 }
6 6
 
7  
-function onLoad() {
8  
-	server.get(new RegExp("^/(.*)$"), hello);
9  
-	server.listen(8080);
10  
-}
  7
+server.get(new RegExp("^/(.*)$"), hello);
  8
+server.listen(8080);
6  memresourced.js
@@ -10,7 +10,5 @@ function on_change(id) {
10 10
 	node.debug(id, JSON.stringify(people[id]));
11 11
 }
12 12
 
13  
-function onLoad() {
14  
-	server.resource("people", server.resourceController("people", people), on_change);
15  
-	server.listen(8080);
16  
-}
  13
+server.resource("people", server.resourceController("people", people), on_change);
  14
+server.listen(8080);
43  todos_backend.js
@@ -39,10 +39,9 @@ function apply_json_to_task(task, json_hash) {
39 39
 
40 40
 // Serialize the data to the disk
41 41
 function save_data() {
42  
-  var file = new node.fs.File();
43  
-  file.open("tasks.db", "w");
44  
-  file.write(JSON.stringify(tasks));
45  
-  file.close();
  42
+  var fd = node.fs.open("tasks.db", node.O_WRONLY, 0666).wait();
  43
+  node.fs.write(fd, JSON.stringify(tasks)).wait();
  44
+  node.fs.close(fd).wait();
46 45
 }
47 46
 
48 47
 // Load the data from the disk
@@ -111,23 +110,19 @@ var tasksController = {
111 110
 	}
112 111
 };
113 112
 
114  
-function onLoad() {
115  
-	
116  
-	// Mount our controller as a RESTful resource
117  
-	server.resource('tasks', tasksController);
118  
-	
119  
-	// Load the datastore
120  
-	puts("Loading data from file...");
121  
-	load_data(function (success) {
122  
-		// Kickoff the server
123  
-		if (success) {
124  
-			puts("Loaded");
125  
-		} else {
126  
-			puts("Error, creating empty tasks array");
127  
-			save_data();
128  
-		}
129  
-		// And start the server when done
130  
-		server.listen(4000);
131  
-	});
132  
- 
133  
-}
  113
+// Mount our controller as a RESTful resource
  114
+server.resource('tasks', tasksController);
  115
+
  116
+// Load the datastore
  117
+puts("Loading data from file...");
  118
+load_data(function (success) {
  119
+	// Kickoff the server
  120
+	if (success) {
  121
+		puts("Loaded");
  122
+	} else {
  123
+		puts("Error, creating empty tasks array");
  124
+		save_data();
  125
+	}
  126
+	// And start the server when done
  127
+	server.listen(4000);
  128
+});

0 notes on commit 83e5929

Please sign in to comment.
Something went wrong with that request. Please try again.