Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:40:20+00:00 2026-05-24T23:40:20+00:00

I am writing a simple test app to experiment with the functionality of node.js

  • 0

I am writing a simple test app to experiment with the functionality of node.js and couchdb, so far i am loving it, but i ran in a snag. i have looked for and wide but can’t seem to find an answer. My test server(a simple address book) does 2 things:

  1. if the user goes to localhost:8000/{id} then my app returns the name and address of the user with that id.
  2. if the user goes to localhost:8000/ then my app needs to return a list a names that are hyperlinks and takes them to the page localhost:8000/{id}.

I was able to get the first requirement working. i cant not seem to find how to retrieve a list of all names from my couchdb. that is what i need help with. here is my code:

var http = require('http');
var cradle = require('cradle');
var conn = new(cradle.Connection)();
var db = conn.database('users');

function getUserByID(id) {
    var rv = "";

    db.get(id, function(err,doc) {
        rv = doc.name;
    rv += " lives at " + doc.Address;
});

return rv;
}

function GetAllUsers() {
var rv = ""
return rv;
}

var server =  http.createServer(function(req,res) {
res.writeHead(200, {'Content-Type':'text/plain'});
var rv = "" ;
var id = req.url.substr(1);

    if (id != "")
    rv = getUserByID(id);
else
    rv = GetAllUsers();

    res.end(rv);


});

server.listen(8000);
console.log("server is runnig");

As you can see, I need to fill in the GetAllUsers() function. Any help would be appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:40:20+00:00Added an answer on May 24, 2026 at 11:40 pm

    You can create a CouchDB view which will list the users. Here are several resources on CouchDB views which you should read in order to get a bigger picture on this topic:

    • Introduction to CouchDB Views
    • Finding Your Data with Views
    • View Cookbook for SQL Jockeys
    • HTTP View API

    So let’s say you have documents structured like this:

    {
        "_id": generated by CouchDB,
        "_rev": generated by CouchDB,
        "type": "user",
        "name": "Johny Bravo",
        "isHyperlink": true
    }
    

    Then you can create a CouchDB view (the map part) which would look like this:

    // view map function definition
    function(doc) {
        // first check if the doc has type and isHyperlink fields
        if(doc.type && doc.isHyperlink) {
            // now check if the type is user and isHyperlink is true (this can also inclided in the statement above)
            if((doc.type === "user") && (doc.isHyperlink === true)) {
                // if the above statements are correct then emit name as it's key and document as value (you can change what is emitted to whatever you want, this is just for example)
                emit(doc.name, doc);
            }
        }
    }
    

    When a view is created you can query it from your node.js application:

    // query a view
    db.view('location of your view', function (err, res) {
        // loop through each row returned by the view
        res.forEach(function (row) {
            // print out to console it's name and isHyperlink flag
            console.log(row.name + " - " + row.isHyperlink);
        });
    });
    

    This is just an example. First I would recommend to go through the resources above and learn the basics of CouchDB views and it’s capabilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I'm writing a simple app that's going to have a tiny form sitting in
I am currently writing a simple, timer-based mini app in C# that performs an
I am writing a simple database with web access. I have previous experience with
I was writing a simple test application. There are two radio buttons within the
I am writing a simple web app using Linq to Sql as my datalayer
I am writing a simple unit test harness in powershell I designed the harness
I'm writing a simple automated test application for Win32. It runs as a separate
I have the following JUnit test. The method that I'm testing is quite simple,
I'm writing a simple P2P application to test the feasibilty of using UDP hole-punching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.