Take the 2-minute tour ×

I need the server-time for "user-is-online" stats in my CouchApp. I work with jquery.couch.js and would prefer to have a url, e.g. /db/_design/app/time - which gets me a timestamp. How do I realize this?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

A show function could do that:

function(doc, req) {
    // _design/myapp/_show/now

    // First version possibly incompatible with some spidermonkey versions.
    //var now = new Date();
    var now = new Date().getTime();
    var output = JSON.parse(JSON.stringify(now)) + "\n";

    return { code: 200
           , body:output

The server also includes a Date header that you might want to use.

$ curl -D- http://localhost:5984
HTTP/1.1 200 OK
Server: CouchDB/1.1.0 (Erlang OTP/R14B)
Date: Fri, 27 May 2011 00:28:31 GMT
Content-Length: 40
Cache-Control: must-revalidate

share|improve this answer
your show function returns '[object, object]' but I changed it to var now = new Date().getTime(); and it worked! Thanks alot! –  juk May 27 '11 at 9:23
Cool. Updated the answer. –  JasonSmith May 27 '11 at 9:27
add comment

Your Answer


