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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:12:44+00:00 2026-06-02T11:12:44+00:00

Here is the thing : I have a client which sends data to a

  • 0

Here is the thing :
I have a client which sends data to a server. This server has to contact an external A.P.I. and send back its response to the client. I just can’t figure out how and where I can contact the external A.P.I once the server has got the client data.

I route client data like this :

app.post('/getAutoComplete', routes.read);

routes.read retrieves the data within req.body. With my nodejs version (without express framework), I then request the api this way :

var http = require('http'), options = {
        host : "192.168.1.38",
        port : 8080,
        path : "/myURL",
        method : 'POST'
};

var webservice_data = "";

var webservice_request = http.request(options, function(webservice_response)
{
    webservice_response.on('error', function(e){ console.log(e.message); });
    webservice_response.on('data', function(chunk){ webservice_data += chunk;});
    webservice_response.on('end', function(){res.send(webservice_data);});
});

webservice_request.write(req.body);
webservice_request.end();

The problem is that i’d like to use native expressJS method like app.post but I don’t know how because :

  1. Express (app) object is not available here (declared in app.js but not in the route file)
  2. I don’t know how to send POST data with app.post

Any suggestion ?

  • 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-02T11:12:48+00:00Added an answer on June 2, 2026 at 11:12 am

    routes.read is a function. You can call it with extra parameters, so for example

    app.post('/getAutoComplete', function(req,res) {
        var q = req.query.q;  // or whatever data you need
        routes.read(q, function(err, response) {
            if (err) throw err;
            return res.json(response);
        });
    });
    

    Now make the routes.read function use the first parameter as the query and when it’s gathered the response from the remote API, call the second parameter with any error as the first parameter and the response as the second one.

    Update This answer has already been picked as an answer, but it’d be more helpful if I showed an example of routes.read, too:

    routes.read = function(q, cb) {
        // pretend we calculate the result
        var result = q * 10;
        if (result > 100) {
            // call the callback with error set
            return cb("q value too high");
        }
        // all is well, use setTimeout to demonstrate
        // an asynchronous return
        setTimeout(function() { cb(null, result) }, 2000);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the thing. Right now I have this e-commerce web site where people
Here is the situation.... I have a iframe, which is located to my client
I'm currently writing a project in Python which has a client and a server
Here is the thing. I currently have a tabBar controller, with several navigation controllers
Here's the thing. I have an interface, and I would to put the Include
I have some doubt on wget command. Here is the thing I want to
I have a problem with docking. Here is the thing. I hope I can
I've set up a simple, single-service server which has been working just fine with
I have a client that I'm wanting to move to a virtual private server.
I write a client-server application which will be sending an .xml file from the

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.