How do i take URL as query string parameter in node.js.
For eg : When i hit browser with the below url:
http://localhost:3000/key1/https://www.google.com/key2/c , I'm unable to get value1 as "https://www.google.com". I'm getting error in browser saying cannot get querystring. But my code works if I replace url with some random string or number.
Below is my code:
var express = require('express');
var app = express();
app.get('/key1/:value1/key2/:value2',function(req,res)
{
var value1 = req.params.value1;
var value2 = req.params.value2;
var spawn = require('child_process').spawn, py = spawn('python',['test.py', value1, value2]);
console.log(req.params);
py.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
res.send(data);
});
py.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
py.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
});
app.listen(3000,function()
{
console.log("Server listenining on port 3000");
});
via Nikita Gupta
No comments:
Post a Comment