Using the request library, I get the get data by request:

 //request.js var request = require('request'); request.get('http://177.77.44.99:8081/gall/cesar.txt',function(error, response, body){ console.log('error:', error); console.log('body:', body); }); 

How can I transfer the received data ( body ) to an ejs template, for example, in $('#traceExport').html(body);

A piece of app.js code

`var routes = require ('./ routes / index');

var users = require ('./ routes / users');

var user_data = require ('./ routes / user_data');

app.use ('/', user_data.router); app.use ('/', routes); app.use ('/ users', users); `

Self users.js

 var router = express.Router(); var request = require('request'); var app = express(); router.get('/login', function (req, res) { res.render("login", {title:"Login page"}); }); 

function handler (req, res) {request.get (' http://177.77.44.99:8081/gall/cesar.txt ', function (error, response, body) {

  res.render('/roumer', {result : body}) }) 

}

router.get ('roumer', handler);

  • Actually, where is your express? You simply make a request to the server, because this is not a request handler. - uber42
  • @ uber42 Well, as if this is the question, how do I pass the result of the query into an ejs form. - Aldem
  • Well, make a request directly in the route handler, and then pass the result for rendering - uber42
  • @ uber42 Thanks for the answer, but when I use this code in my example I get a 404 error, i.e. as if the path to my page is not correct (/ roumer), and how to implement it in cases if I need to display the file by pressing a button in a certain form, well, I understand how to do ajax'om, and how to implement it in node js? - Aldem
  • Do you get an error when sending a GET request to the address / path? And attach your code, sketches and what errors in what cases - uber42

1 answer 1

 function handler(req, res){ request.get('http://177.77.44.99:8081/gall/cesar.txt',function(error, response, body){ if(error) { // res.redirect('/') ответ в результате ошибки } else { res.render('name.ejs', {result : body}) } }) } app.get('path', handler);