I'm trying to get parameters from a URL, for example:
http://localhost:8888/?name=test
To get name
parameter I saw some samples where they use the url
module like this:
var url = require('url');
var urlParts = url.parse(request.url, true);
var query = urlParts.query;
So, first I ran this command npm install url
, also the dependency is on the package.json
file, but I always get this error:
TypeError: Cannot call method 'parse' of undefined
at C:\Users\Administrator\git\test\app.js:28:7
Anyone has faced this problem before?
I found the problem, I had the code like this:
And the
url
object was not accessible inside thecreateServer
function (not sure why), so I just replace this line:with this:
and now is working fine.
This one bit me too - my problem was that
url.parse
was conflicting with a local varurl
. I solved it like this:Thanks @loganfsmyth for the insight!