You need to parse the URL inside of your routing function, where the req
variable lives.
app.get("/page", function(req, res) {
var path = url.parse(req.url).pathname;
}
And yes, you can then compare the path to a string.
On Friday, January 10, 2014 2:50:00 PM UTC-5, JPJen wrote:
>
> 0 down vote
> favorite<http://stackoverflow.com/questions/21051809/typeerror-parameter-must-be-a-string-while-parsing-a-url/21051889?noredirect=1#>
>
>
> I have two questions.
>
> I have a code snippet below
>
> var http = require('http'),
> https = require('https'),
> crypto = require('crypto');var S = require('string');var url =
> require('url');var req = require('request');
> var path = url.parse(req.url).pathname;
>
> The error message points at
>
> var path = url.parse(req.url).pathname;
>
> saying throw new TypeError("Parameter 'url' must be a string. not " +
> typeof url)
>
> What is wrong with that statemet? Do I have to put that statement in a
> function? But, I do not know what function I should create for dong url
> parsing.
>
> My second question refers to the code snippet below. Can I compare the
> path that I extract from a URL and compare it with a string using *==* ?
>
> if ((S(path) == '/lens/v1/ping') || (S(path) == '/lens/v1/PING')) {
> res.writeHead(200, {'Content-Type': 'text/plain'});
> res.write('The lens route is up and running!\n');
> res.end();} else {
> res.writeHead(404, 'Not Found');
> res.end('HTTP 1.1 404/Not Found');}
>
> Thank you very much in advance.
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.