我正在使用Node.js和Express创建REST API。服务器启动于localhost:xxxx
,但localhost:xxxx/bits
返回404错误。
var express = require('express');
var app = express();
app.get('/bits', function(req, res) {
console.log("Bits called");
});
app.get('/bits/:id', function(req, res) {
console.log("Bits ID called");
});
app.listen(xxxx);
console.log('Listening on port xxxx.');
Help?
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(83, 'localhost'); console.log('Server running at http://127.0.0.1:83/');
它打印出了“Hello World”。 - pxthxk127.0.0.1:83
而不是localhost:83
。我的system32主机文件中有127.0.0.1 localhost
。可能的原因是什么? - pxthxkping -4 localhost
,看看它认为 localhost 是哪个 IP 地址。 - jfriend00