I try to parse a request with node.js, So I build the next:
app.get('/download', function(req, res){
var parseJson = JSON.parse(req);
var file = parseJson.fileName;
res.download(file); // Set disposition and send it.
});
And I send a request with the Advanced Rest Client:
URL: http://localhost:5000/download
Method: GET
Raw arguments: fileInfo: "C://1//239698_n.jpg"
and it gives me the next error:
SyntaxError: Unexpected token o
at Object.parse (native)
at port (c:\Node\nodejs\express.js:13:24)
at callbacks (c:\Node\nodejs\node_modules\express\lib\router\index.js:164:37)
at param (c:\Node\nodejs\node_modules\express\lib\router\index.js:138:11)
at pass (c:\Node\nodejs\node_modules\express\lib\router\index.js:145:5)
at Router._dispatch (c:\Node\nodejs\node_modules\express\lib\router\index.js:173:5)
at Object.router (c:\Node\nodejs\node_modules\express\lib\router\index.js:33:10)
What can be the reson?
requestand confirming it is valid JSON?JSON.parsestep. I don't think the data you want is inreq, but ratherreq.query