Javascript 如何获取字符串路径名?

Javascript 如何获取字符串路径名?,javascript,node.js,Javascript,Node.js,如何获取字符串路径名 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'

如何获取字符串路径名

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!');

没有错误输出,但没有显示请求…

这似乎对我有效:

FL261:~ jvah$ node pathname
Server me!
Request for / received.
同时在另一个窗口中使用curl:

FL261:~ jvah$ curl http://127.0.0.1:8124/
Hello

这似乎对我有用:

FL261:~ jvah$ node pathname
Server me!
Request for / received.
同时在另一个窗口中使用curl:

FL261:~ jvah$ curl http://127.0.0.1:8124/
Hello
有关日志记录,请参阅本文:有关日志记录,请参阅本文: