I have a problem with using nodejs and express, I have never used this language and I do not have much knowledge of it so I will try to be as specific as possible here.
1 I have a webservice rest that returns me purchase orders with several items but summarizing it would be something like this
{ "nrSolicCompra": "94705", "applicant": "JSilva", "items": {"cd Material": "259560", "DsMaterial": "flat head nails", "qtMaterial": "1000" } }
I need to get this json and it shows in the front end (which is in EJS nodejs)
I currently have the following structure.
A page called index.js where I have the following code I found on the net:
var express = require('express');
var router = express.Router();
router.get('/teste', function(req, res, next) {
res.render('teste', { variavel: 'passou no teste', solicitacaoCompra: solicitacaoCompra })
});
var http = require('http');
var options = {
host: 'localhost',
port: 8080,
path: '/meuWebService/metodoRetorno',
mothod: 'GET'
};
var solicitacaoCompra;
http.request(options, function(res) {
var body = "";
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
solicitacaoCompra = JSON.parse(body);
})
}).end();
module.exports = router;
on page teste.ejs I can put this code in order to print json
<%- JSON.stringify(solicitacaoCompra) %>
and it prints in string what I need but I'm not able to store that in a variable or do a html formatting to get on a perfect list something like
<table>
<th> numero pedido</th>
<th> solicitante</th>
</table>
The initial table would be just that and when the user clicks on a button called visualization it would appear a modal with the items of that request.