【发布时间】:2020-06-05 19:59:40
【问题描述】:
我刚开始学习 Node.js,但遇到了服务器问题。我尝试了各种解决方案,但都不起作用(更改端口、更新 node.js、更新 chrome 等),但没有任何效果。
服务器打开,但本地主机没有响应。
这是我的 index.js 文件
const app = express();
const port = 3000;
app.get("/", (req, res) => {
console.log("test");
res.send("Hello world");
});
app.listen(port, () => {
console.log(`Server open port ${port}`);
});
这是我的 package.json 文件
"name": "last-server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
终端视图
$ node app.js
Server open port 3000
test
test
test
test
**服务器启动,但在 Chrome 中没有得到 localhost 的响应。不过,相同的代码在我朋友的设备中也可以使用。 **
【问题讨论】:
标签: javascript node.js express server