我所做的一切都正确。它也可以在console.log中工作,但不能在本地端口的浏览器中工作。请帮助
var express = require("express");
var app = express();
app.get("/", function(req, res){
res.send("Hi there, welcome to my assingment");
})
app.get("/speak/goat", function(req, res){
res.send('The goat says "Oink"');
})
app.get("/speak/dog", function(req, res){
res.send('The dog says "Bow"');
})
app.get("/speak/goat", function(req, res){
res.send('The goat says "Oink"');
})
app.get("/repeat/:anything/:value", function(req, res){
var anyThing = req.params.anything;
var value = req.params.number.value;
for(i = 0 ; i >= value ;i++ ){
res.send(anyThing);
}
})
var PORT = process.env.PORT || 6000;
app.listen(PORT, function(){
console.log("hello " + PORT);
});
好像您正在尝试在chrome上打开localhost:6000,这导致生成“ ERR_UNSAFE_PORT”-这是因为使用了非标准端口。您可以使用其他端口示例3000或4000甚至6001。-Internet Explorer在端口6000上工作:-)
在此处找到更多https://douglastarr.com/how-to-allow-unsafe-ports-in-chrome