Olá,
seguindo as instruções do professor, fiz o cadastra-livros-terminal.js mas o JSON.stringify parece não resolver muito. quando executo o codigo me retorna o seguinte erro no server:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at Query.Sequence._packetToError (C:\wamp\www\casadocodigo\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Query.ErrorPacket (C:\wamp\www\casadocodigo\node_modules\mysql\lib\protocol\sequences\Query.js:77:18)
at Protocol._parsePacket (C:\wamp\www\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\wamp\www\casadocodigo\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\wamp\www\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\wamp\www\casadocodigo\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
--------------------
at Protocol._enqueue (C:\wamp\www\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at Connection.query (C:\wamp\www\casadocodigo\node_modules\mysql\lib\Connection.js:208:25)
at ProdutosDAO.salva (C:\wamp\www\casadocodigo\app\infra\ProdutosDAO.js:11:19)
at C:\wamp\www\casadocodigo\app\routes\produtos.js:38:17
at Layer.handle [as handle_request] (C:\wamp\www\casadocodigo\node_modules\express\lib\router\layer.js:95:5)
at next (C:\wamp\www\casadocodigo\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\wamp\www\casadocodigo\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\wamp\www\casadocodigo\node_modules\express\lib\router\layer.js:95:5)
at C:\wamp\www\casadocodigo\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\wamp\www\casadocodigo\node_modules\express\lib\router\index.js:335:12)
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\' at line 1',
sqlState: '42000',
index: 0,
sql: 'insert into livros set ' }
o meu client está da seguinte maneira :
var http = require("http");
var config = {
hostname : 'localhost',
port : 3000,
path : '/produtos',
method : 'post',
headers :{
'Accept':'Application/json'
}
}
var client = http.request(config, function(res){
console.log(res.statusCode);
res.on('data', function(body){
console.log('corpo' + body);
});
})
var produto = {
nome : 'node: backend em js',
author: 'James Anaker',
lancamento: '2017-08-15'
}
client.end( JSON.stringify(produto) );
como resolvo isso?