← helloexpress

update a view count of a file, basic

44fcabf2d99cbcca125a7ec53fcb96d226aa7ad9 · ovidiucs · Apr 17, 2014 18:46

+13 · 2 files changed

  • app.js +12 −0
  • public/hello.txt +1 −0
diff --git a/app.js b/app.js
index 9818e18..b7731f9 100644
--- a/app.js
+++ b/app.js
@@ -37,6 +37,18 @@ app.get("/users/:from-:to", function (req, res) {
        res.json(newlist.slice(req.from, req.to + 1));
 }); 
 
+var count  = 0;
+
+app.get('/hello.txt', function (req, res, next) {
+   count+=1;
+   // go to next middleware
+   next();
+});
+
+app.get('/count', function (req, res) {
+   res.send(" ", + count + " views");
+});
+ 
 http.createServer(app).listen(app.get("port"), function(){
   console.log("Express server listening on port " + app.get("port"));
 });
diff --git a/public/hello.txt b/public/hello.txt
new file mode 100644
index 0000000..10ddd6d
--- /dev/null
+++ b/public/hello.txt
@@ -0,0 +1 @@
+Hello!