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 8975163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:48:33+00:00 2026-06-15T18:48:33+00:00

I have the following code: var http = require(‘http’) ,https = require(‘https’) ,fs =

  • 0

I have the following code:

var http = require('http')
  ,https = require('https')
  ,fs = require('fs'),json;

var GOOGLE_API_KEY = process.env.GOOGLE_API_KEY;

var FUSION_TABLE_ID = "1epTUiUlv5NQK5x4sgdy1K47ACDTpHH60hbng1qw";

var options = {
  hostname: 'www.googleapis.com',
  port: 443,
  path: "/fusiontables/v1/query?sql=SELECT%20*%20"+FUSION_TABLE_ID+"FROM%20&key="+GOOGLE_API_KEY,
  method: 'GET'
};

http.createServer(function (req, res) {
  var file = fs.createWriteStream("chapters.json");
  var req = https.request(options, function(res) {
    res.on('data', function(data) {
      file.write(data);
    }).on('end', function() {
      file.end();
    });
  });
  req.end();
  req.on('error', function(e) {
    console.error(e);
  });
  console.log(req);
  res.writeHead(200, {'Content-Type': 'application/json'});
  res.end('Hello JSON');

}).listen(process.env.VMC_APP_PORT || 8337, null);

how do i return the json object rather then the ‘Hello JSON’?

  • 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-06-15T18:48:34+00:00Added an answer on June 15, 2026 at 6:48 pm

    Don’t store the received data in a file, put it in a local variable instead, and then send that variable in res.end():

    var clientRes = res;
    var json = '';
    
    var req = https.request(options, function(res) {
        res.on('data', function(data) {
            json += data;
        }).on('end', function() {
            // send the JSON here
            clientRes.writeHead(...);
            clientRes.end(json);
        });
    });
    

    Note that you have two res variables – one for the response you’re sending back to your own clients, and one which is the response you’re receiving from Google. I’ve called the former clientRes.

    Alternatively, if you’re just going to proxy the information unmodified, you can just put clientRes.write(data, 'utf8') inside the res.on('data') callback:

    http.createServer(function (clientReq, clientRes) {
    
        var req = https.request(options, function(res) {
            res.on('data', function(data) {
                clientRes.write(data, 'utf8');
            }).on('end', function() {
                clientRes.end();
            });
    
        clientRes.writeHead(200, {'Content-Type: 'application/json'});
        clientReq.end().on('error', function(e) {
            console.error(e);
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following node.js server-side code: var app = require('http').createServer(handler) , io =
in socket.io 0.6, i have following example code: var io = require('/usr/lib/node_modules/socket.io'); var server
I have the following code: var express = require('express'); var app = express.createServer(); var
I have the following simple http server using Node.js: var http = require('http'); var
I have the following Node.js code: var express = require('express'); var app = express.createServer(express.logger());
I have the following code in server/statusboard.js; var require = __meteor_bootstrap__.require, request = require(request)
I have the following code: var submitHandler = function ($link, $form, close) { var
I have the following code: var refreshId = setInterval(function() { $(#footad).html('myjshere'); }, 15500); Where
I have the following code: var carsContext = new CarsDataContext(); IQueryable<Car> allCars = carsContext.Cars;
I have the following code var dbvalue = Ned; var deleteLink = '<a href=#delete

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.