![](/img/trans.png)
[英]Node.js App Error: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined"
[英]Node.js TypeError: Parameter 'url' must be a string, not undefined
我試圖使用url模塊和http服務器解析一些網址。
代碼如下:
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);
給出以下錯誤:
TypeError: Parameter 'url' must be a string, not undefined
在這一行:
var parsedURL = URL.parse(req.URL, true).pathname;
有人可以幫忙嗎? 任何解釋將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.