node.js – Error while registering

I am trying to register with my API and have the following route:

app.post (& # 39; / api / novoconveniado & # 39 ;, function (req, res) {

var name = req.body.name;
var category = req.body.category;
var address = req.body.endereco;
var neighborhood = req.body.boirro;
var city = req.body.city;
var phone = req.body.telephone;
var cellular = req.body.cellular;
varContractTitle = req.body.ofertaContratualTitle
varContractContractDescription = req.body.oferConContractDesconto;
varContract = req.body.Contract;
varContractContractDescription = req.body.ContractContractDescription;
var email = req.body.email;
var password = req.body.password;
var referral = req.body.id + "CRED" + Math.random () * (100000 - 2) + 2;
var image = req.body.image.replace (/ / g, "+");

var body = {
nvc_name: name,
nvc_category: Category,
nvc_email: email,
nvc_phone: phone,
nvc_status: "W",
nvc_endereco: address + "" + environment + "" + city,
nvc_bonus: "",
nvc_custo: "",
nvc_password: password,
nvc_data: new date (Date.now ()). toLocaleString (),
nvc_referral: transfer,
nvc_s picture
}
const id = "??"; // missing selection from another table
const cont = "Y";

var corpopromocontratual =
pro_titulo: SupplyContratualTitulo,
pro_descricao: offerContratualDescricao,
pro_desconto: offerContratualDesconto,
pro_data: "sysdate ()",
pro_custo: contract offer,
pro_category: category,
pro_contractual: cont,
id: id
}

var sql = "INSERT INTO nvc_new_recognized SET?";
var sql2 = & # 39; INSERT IN pro_promotion (pro_titulo, pro_descricao, pro_data, pro_data, nvc_id, pro_categoria, pro_custo, pro_contratual) VALUES (& # 39; + & # 39; + corpopromocontratual.pro_titulo + & # 39; & # 39; & # 39; 39 & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; # 39; & # 39; & 39; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; ; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; # 39; & # 39; & 39; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; ; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; # 39; & # 39; & 39; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; ; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; # 39; & # 39; & 39; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; ; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; # 39; & # 39; & 39; & # 39; & 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; ; & # 39; & 39; & # 39; 39 & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; & # 39; 39; + & # 39; + corpopromocontratual. pro_data + #, # + corpopromocontratual.ide + #, & # 39; + & # 39; & # 39; & # 39; + corpopromocontratual.pro_categoria + & # 39 ;, & # 39; + & # 39 ;, & # 39; & # 39; & # 39; & # 39; + corpopromocontratual.pro_custo + & # 39; & # 39; & # 39; + & # 39 ;, & # 39; + & # 39; & # 39; & # 39; + corpopromocontratual.pro_contratual + & # 39; & # 39; & # 39; + & # 39;) & # 39 ;;

connection.query (sql, body, function (err, result))
try it
res.status (200) .send ({result});
connection.query (sql2, corpopromocontratual, function (err, result))
try it
res.status (200) .send ({result});
console.log (sql2);
catch (err) {
res. status (500);
console.log (err);
}
})
catch (err) {
res. status (500);
console.log (err);
}
});
});

When I do the test at the postman, however, I get the following exception:

Error: Headers can not be set after they have been sent.
at validateHeader (_http_outgoing.js: 491: 11)
at ServerResponse.setHeader (_http_outgoing.js: 498: 3)
at ServerResponse.header (/root/Api/novaApiProj/node_modules/express/lib/response.js:767:10)
at ServerResponse.send (/root/Api/novaApiProj/node_modules/express/lib/response.js:170:12)
ServerResponse.json (/root/Api/novaApiProj/node_modules/express/lib/response.js:267:15)
at ServerResponse.send (/root/Api/novaApiProj/node_modules/express/lib/response.js:158:21)
at query. (/Root/Api/novaApiProj/app.js:444:45)
at query. (/Root/Api/novaApiProj/node_modules/mysql/lib/Connection.js:502:10)
at Query._callback (/root/Api/novaApiProj/node_modules/mysql/lib/Connection.js:468:16)
at Query.Sequence.end (/root/Api/novaApiProj/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
at Query.ErrorPacket (/root/Api/novaApiProj/node_modules/mysql/lib/protocol/sequences/Query.js:90:8)
at Protocol._parsePacket (/root/Api/novaApiProj/node_modules/mysql/lib/protocol/Protocol.js:278:23)
at Parser.write (/root/Api/novaApiProj/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/root/Api/novaApiProj/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at socket. (/Root/Api/novaApiProj/node_modules/mysql/lib/Connection.js:91:28)
at socket. (/Root/Api/novaApiProj/node_modules/mysql/lib/Connection.js:502:10)

I could not understand the reason for the mistake because I have similar routes.