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

  • Home
  • SEARCH
  • 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 6376561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:45:40+00:00 2026-05-25T01:45:40+00:00

I am using the sample code from nodejs.org and trying to send the response

  • 0

I am using the sample code from nodejs.org and trying to send the response to the browser .

var http = require("http");
var port = 8001;
http.createServer().listen(port);
var options = {
  host: "xxx",
  port: 5984,
  //path: "/_all_dbs",
  path: "xxxxx",
  method: "GET"
};

var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
      var buffer = "";
      buffer += chunk;
      var parsedData = JSON.parse(buffer);
      console.log(parsedData);
      console.log("Name of the contact "+parsedData.name);
  });
});

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

req.write(“hello”);
req.end();

But req.write(“hello”) just does not output the string to the browser ?
Is this not the right way ? can someone also tell me how to output the response to the html in views folder so that i can populate the response to the static html .

  • 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-25T01:45:42+00:00Added an answer on May 25, 2026 at 1:45 am

    Try this:

    var http = require('http');
    
    var options = {
      host: "127.0.0.1",
      port: 5984,
      path: "/_all_dbs",
      method: "GET"
    };
    
    http.createServer(function(req,res){
        var rq = http.request(options, function(rs) {
            rs.on('data', function (chunk) {
                res.write(chunk);
            });
            rs.on('end', function () {
                res.end();
            });
        });
        rq.end();
    }).listen(8001);
    

    Edit:

    This node script saves the output to a file:

    var http = require('http');
    var fs=require('fs');
    
    var options = {
      host: "127.0.0.1",
      port: 5984,
      path: "/_all_dbs",
      method: "GET"
    };
    var buffer="";
    var rq = http.request(options, function(rs) {
        rs.on('data', function (chunk) {
            buffer+=chunk;
        });
        rs.on('end', function () {
            fs.writeFile('/path/to/viewsfolder/your.html',buffer,function(err){
                if (err) throw err;
                console.log('It\'s saved!');            
            });
        });
    });
    rq.end();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to send MMS using code sample from here . I am
I'm going to use the sample code from http://gettinggeneticsdone.blogspot.com/2009/11/split-apply-and-combine-in-r-using-plyr.html for this example. So, first,
I'm trying to connect to Informix database using sample code from https://www.ibm.com/developerworks/data/library/techarticle/dm-0510durity/ I'm using
I am using the example from TheElements sample code provided with the iPhone SDK
Here is a sample code to retrieve data from a database using the yield
I've built an iPhone application using the parsing code from the TopSongs sample iPhone
I am using some code which was originally taken from the Apple sample ViewTransitions
I am using Reachability sample code from Apple site. I have added Reachability.h and
I am using the sample code to dynamically invoke a web service from this
I'm trying to learn how to do XPath queries from Python using this sample

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.