admin管理员组文章数量:1356304
Im trying to parse some urls using url module and http server.
Code bellow:
var http = require('http');
var URL = require('url');
var port = 8080;
var server = http.createServer(function(req, res) {
var parsedURL = URL.parse(req.URL, true).pathname;
switch(parsedURL) {
case 'test/myurl':
console.log('Valid URL.');
break;
default:
console.log('404!')
}
});
server.listen(port);
console.log('Service at port: ' + port);
gives following error:
TypeError: Parameter 'url' must be a string, not undefined
at this line:
var parsedURL = URL.parse(req.URL, true).pathname;
Anyone can help? Any explanation would be appreciated.
Im trying to parse some urls using url module and http server.
Code bellow:
var http = require('http');
var URL = require('url');
var port = 8080;
var server = http.createServer(function(req, res) {
var parsedURL = URL.parse(req.URL, true).pathname;
switch(parsedURL) {
case 'test/myurl':
console.log('Valid URL.');
break;
default:
console.log('404!')
}
});
server.listen(port);
console.log('Service at port: ' + port);
gives following error:
TypeError: Parameter 'url' must be a string, not undefined
at this line:
var parsedURL = URL.parse(req.URL, true).pathname;
Anyone can help? Any explanation would be appreciated.
Share Improve this question asked Oct 15, 2016 at 3:41 JacsJacs 1,5374 gold badges22 silver badges33 bronze badges 1-
1
try using
req.url
– Anuj Commented Oct 15, 2016 at 4:19
1 Answer
Reset to default 3The url property name for an http.IningMessage
object is:
req.url
not
req.URL
thus, req.URL
is undefined
.
本文标签: javascriptNodejs TypeError Parameter 39url39 must be a stringnot undefinedStack Overflow
版权声明:本文标题:javascript - Node.js TypeError: Parameter 'url' must be a string, not undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743965148a2569748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论