2013-11-15 119 views
1

如何獲取字符串路徑名?如何獲取字符串路徑名?

var http=require('http'); 
var url = require("url"); 
http.createServer(function(req,res){ 


var pathname = url.parse(req.url).pathname; 
console.log("Request for " + pathname + " received."); 



res.writeHead(200,{'Content-Type':'text/plain'}); 
res.end('Hello\n'); 
}).listen(8124,'127.0.0.1'); 
console.log('Server me!'); 

沒有錯誤輸出,但不顯示請求....

+0

看到這篇文章的日誌:http://stackoverflow.com/questions/3459476/how-to-append-to-a-file-in-node –

回答

1

這似乎爲我工作:

FL261:~ jvah$ node pathname 
Server me! 
Request for/received. 

而在其他窗口同時使用curl:

FL261:~ jvah$ curl http://127.0.0.1:8124/ 
Hello 
相關問題