I'm trying to use an api in nodejs but I can not pass the parameters the req.body is empty and I can not identify the problem
var express = require('express') var app = express() var bodyParser = require('body-parser') var core_use = require('cors'); var sql = require("mssql");app.use(core_use()); app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: true }));
var retorno = { method: '', uri: '', response: [] };
app.get('/consultarCartaoSus', function (req, res) { sql.connect(config, function (err) { var request = new sql.Request(); console.log(req.body); // query to the database and get the records '' request.query('select * from clientes ', function (err, response) { if (err) { sql.close(); console.log(err); }; retorno.method = 'GET'; retorno.uri = 'consultarCartaoSus'; retorno.response = response.recordsets;
res.setHeader('Access-Control-Allow-Origin', '*'); res.json(retorno); sql.close(); }); });