New to NodeJS: Utilizing Requestify to Retrieve Data from Another URL

As a newcomer in the world of NodeJs, I am faced with the task of transitioning my CodeIgniter server APIs to Node.js. Currently, I am utilizing requestify to retrieve data from a web service, and once this is accomplished, I intend to invoke an insert method to store all the entries.

requestify.get('SERVER_URL_CODE_IGNITER_API')
   .then(function(response) {
      // My concern here is that the JSON elements retrieved contain escape characters,
      // which I wish to avoid
      res.jsonp(response.body);

      // Attempting to use the following line results in an error
      // Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND',
      // syscall: 'getaddrinfo 
      // response.getBody();
   });

I believe that using response.getBody() should provide me with the desired output without the presence of escape characters. However, despite my efforts, I have been unable to make it work while response.body does function but introduces backward slashes within the server data, for example:

"[{\"id\":\"212\",\"uid\":\"304\",\"fromLat\":\"28.5962491\",\"fromLon\":\"77.3396212\",\"toLat\":\"28.4594965\",\"toLon\":\"77.0266383\",\"fromName\":\"Sector 12, Noida, Uttar Pradesh, India\",\"toName\":\"Gurgaon, Haryana, India\",\"startTime\":\"08:00 Hrs\",\"returnTime\":\"06:40 Hrs\",\"carModel\":\"suzuki baleno\",\"fuelType\":\"CNG\",\"chargePrice\":\"\",\"smoking\":\"Doesnt Matter\",\"name\":\"Ankur Gupta\",\"image\":\"http:\/\/graph.facebook.com\/100000725036031\/picture?type=large\",\"email\":\"

Answer №1

When utilizing response.getBody(), the response is not actually sent to the client. It seems like you are attempting to send the response to the client, in which case you should use

res.jsonp(response.getBody());

The response.body method only provides the raw response body. You can also use

console.log(response.body); 

and

console.log(response.getBody()); 

for comparison of your output.

If I had to guess, are you using the express framework? Your request handler should be structured like this:

function(req, res){
  //other codes
  requestify.get('SERVER_URL_CODE_IGNITER_API')
    .then(function(response) {
       res.jsonp(response.getBody());
    });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Miniconda completed the installation of Yarn, however, the versions of npm and Nodejs that came with it are

Hey there, I'm looking to use miniconda for a small FARM project involving FastApi, React, and MongoDB. I prefer to use the Yarn package manager, but I'm running into some frustration because I can't upgrade Node.js and npm. conda create --n ...

Typedoc Error: Attempted to assign a value to an undefined option (mode)

After installing typedoc with the command npm install typedoc --save-dev, I proceeded to add typedocOptions to tsconfig.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", // ...some lin ...

Implementing styling upon app mounting in Vue.js - a step-by-step guide

Hey, I'm working with a template code that looks like this: Here's my script code: data () { return { loadPage: true } }, mounted () { this.loadPage = true }, And here is my styling code: #app{ width: 100%; opacit ...

Avoiding scrolling when a button (enveloped in <Link> from react-scroll) is pressed in React

Currently, I am implementing the smooth scroll effect on a component using react-scroll. However, adding a button inside the component to create a favorite list has caused an issue where the smooth scroll effect is triggered upon clicking the button. Is ...

Having trouble passing data from router to View with EJS in Express. Despite trying, still encountering ReferenceError message

I encountered an issue when trying to display form errors to the user. I attempted to pass the errors from the router to my view file. Error Message ReferenceError: e:\2016\passport\views\register.ejs:38 36| 37| <div ...

How to retrieve TypeScript object within a Bootstrap modal in Angular

Unable to make my modal access a JavaScript object in the controller to dynamically populate fields. Progress Made: Created a component displaying a list of "person" objects. Implemented a functionality to open a modal upon clicking a row in the list. ...

Bringing back a Mongoose Aggregate Method to be Utilized in Angular

I'm having trouble returning an aggregate function to Angular and encountering errors along the way. I would really appreciate some assistance with identifying the mistake I am making. The specific error message I receive is Cannot read property &apos ...

Tips for utilizing variables as the initial value of a JSON Object

Here is a JSON configuration example: { "Users" : { "182723618273612" : 15, "AddedUser" : 1 } } I have generated this field using a JavaScript function, but now I want to change the name of "AddedUser" ...

Error: The function 'handle' cannot be invoked as it is undefined

Attempting to set up a basic http server with node js, focusing on listening to a specific port. Encountering an error resembling the following: /usr/local/lib/node_modules/express/lib/application.js:123 this._router.handle(req, res, function(err) { ...

tslint issues detected within a line of code in a function

I am a novice when it comes to tslint and typescript. Attempting to resolve the error: Unnecessary local variable - stackThird. Can someone guide me on how to rectify this issue? Despite research, I have not been successful in finding a solution. The err ...

Node.js OTP Verification: Secure your app with one-time

How can the accuracy of OTPs received from clients be verified effectively in a Node environment without relying on additional storage methods? ...

Master the Art of Animating Letters in the DOM by Navigating Through Any Array of Characters

I am attempting to implement a typewriter effect animation where a new message is displayed and animated as I type into an input box. Initially, I tried using a global char variable to iterate through each element of the array. However, whenever I passed ...

Methods to Maintain Consistent HTML Table Dimensions utilizing DOM

I am facing an issue with shuffling a table that contains images. The table has 4 columns and 2 rows. To shuffle the table, I use the following code: function sortTable() { // Conveniently getting the parent table let table = document.getElementById("i ...

Storing data in a table created through a belongsToMany relationship in Sequelize and retrieving it. (Solution provided below)

My backend setup includes Node.js, Express.js, and Sequelize for database connections. I have established a many-to-many relationship between Tasks and Keys. I defined the connection between Tasks and Keys using Sequelize as follows: Backend // Task ...

Obtaining a specific item from a group using AngularJS. Utilizing a declarative method

Consider a scenario where you need to apply a CSS rule to a specific element within a collection that needs to be selected. <div ng-repeat="fragments" ng-click="makeSelected()"></div> $scope.fragments = [ {id: 6379, someProperty: "someValu ...

Why is npm generating such a large amount of files?

After reviewing this section of the PhpStorm manual, I believe I found a workaround for adding a development tool: If a tool is solely for documentation or testing purposes and not necessary for application reusability, it's best to exclude it from f ...

Is it possible to identify the beginning of a download using Selenium?

Currently, I am using Python and Selenium to download a large batch of files. To ensure that each file is successfully downloaded, I am implementing a basic time.sleep() function, but I want to enhance efficiency and guarantee the completion of each downlo ...

The callback in Jquery getJSON does not execute even when a valid JSON response is received

My server is sending valid JSON objects (as verified by jsonlint.com) that have this structure: "{\"encryption\": {\"key\": \"gKV0oPJwC5CBQxmn\"}}" This is how my HTML file looks: <html> <head> <title&g ...

Making a REST API call with an ID parameter using Angular

I am currently working on an Angular application that interacts with a REST API. The data fetched from the API is determined based on the customer ID, for example: api/incident?customer_id=7. I am unsure of how to incorporate this into the API URL and serv ...

Is it possible to use a JavaScript string as a selector in jQuery?

So, my issue is with the following JavaScript code snippet: for ( i=0; i < parseInt(ids); i++){ var vst = '#'+String(img_arr[i]); var dst = '#'+String(div_arr[i]); } I'm wondering how I can proceed in jQuery to handle ...