Node.js: Read Params Passed In The Url
In rails I do a POST request to my server: response = Typhoeus::Request.post('http://url.localtunnel.com/request?from=ola&to=ole') result = JSON.parse(response.body) In the No
Solution 1:
The answer is:
Checks query string params(req.query), ex: ?id=12
Solution 2:
Something like this:
var http = require('http'), url = require('url');
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type":"text/plain"});
var _url = url.parse(request.url, true);
response.write("Hello " + _url.query["from"] + "!\n"); // etc: _url.query["to"]...
response.close();
}).listen(8000);
url.parse
is a key point... Or you can use querystring.parse(urlString)
You can read more at http://nodejs.org docs section.
Post a Comment for "Node.js: Read Params Passed In The Url"