There is a site on which requests from the client come to the server originally written on noodejs. And the whole apishka, for receiving data, is located on another server written in php. Accordingly, you need to constantly send from nodejs php api requests for data. Can you please tell me if there are any built-in methods for node.js? Or maybe there are some libraries?

1 answer 1

There is such a library: https://www.npmjs.com/package/request An example of a correct query using it:

var request = require('request'); request('http://www.google.com', function (error, response, body) { console.log('error:', error); // Print the error if one occurred console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received console.log('body:', body); // Print the HTML for the Google homepage. }); 
  • Thank. I think this one will do. But in this case, we actually make another request to the server. And if the php server and the node.js server are physically running on the same physical server (computer), is there any way to do this more optimally, can you go to another directly from one program? Or is there nothing like that? - vvtvvtvvt1 pm
  • nah Communicating via localhost is quite a working scheme. Interaction with the database in the same way. If you do not like it - contact the client directly to the php-server, directly - Dmytryk