couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [13/15] couchdb-nano git commit: Update express.js example for nano 6 and express 4
Date Wed, 11 Jan 2017 11:46:00 GMT
Update express.js example for nano 6 and express 4

There were a few places where this file was out of date.

Express 4:
* express.createServer() has been deprecated
* passing the status via send() has been deprecated
* convention is to use 'req' and 'res' instead of 
  'request' and 'response'  

Nano 6:
* error['status-code'] is now error.statusCode

Also there was a syntax error (too many curly braces).

Project: http://git-wip-us.apache.org/repos/asf/couchdb-nano/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nano/commit/6be3aec6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nano/tree/6be3aec6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nano/diff/6be3aec6

Branch: refs/heads/master
Commit: 6be3aec6dad6f035139bf38e58d39f4e38a8955a
Parents: 3db2d95
Author: phil manijak <github@exclsr.com>
Authored: Mon May 9 00:37:41 2016 -0700
Committer: Glynn Bird <glynn.bird@gmail.com>
Committed: Wed Oct 26 14:38:01 2016 +0100

----------------------------------------------------------------------
 examples/express.js | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/6be3aec6/examples/express.js
----------------------------------------------------------------------
diff --git a/examples/express.js b/examples/express.js
index 51dceac..b49ba1d 100644
--- a/examples/express.js
+++ b/examples/express.js
@@ -12,16 +12,19 @@
 
 var express = require('express')
    , db    = require('nano')('http://localhost:5984/my_couch')
-   , app     = module.exports = express.createServer()
+   , app     = module.exports = express()
    ;
 
-app.get('/', function(request,response) {
-    db.get('foo', function (error, body, headers) {
-      if(error) { return response.send(error.message, error['status-code']); }
-      response.send(body, 200);
-    });
-  });
+app.get('/', function(req, res) {
+   db.get('foo', function (error, body, headers) {
+      if(error) {
+         res.status(error.statusCode);
+         return res.send(error.message); 
+      }
+      res.status(200);
+      res.send(body);
+   });
 });
 
 app.listen(3333);
-console.log('server is running. check expressjs.org for more cool tricks');
+console.log('server is running. check expressjs.com for more cool tricks');


Mime
View raw message