gpt4 book ai didi

javascript - Nodemon 不重新加载页面

转载 作者:行者123 更新时间:2023-12-02 23:46:53 24 4
gpt4 key购买 nike

我正在开始学习 Node.js,因此我使用 nodemon 重新加载我的页面,但它不起作用,并且已经尝试了所有 Stack 解决方案。

看看我的代码有多简单:

package.json

{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4"
},
"devDependencies": {
"nodemon": "^1.18.3"
}
}

server.js

const express = require('express');

const app = express();

app.get('/', (req, res) => {
res.send('Hey');
});

app.listen(3001);

res.send() 消息交互时的 bash。 enter image description here

最佳答案

您正在服务器上使用nodemon。当您对 server.js 文件进行更改时,它会重新启动服务器。也就是说,您的端点正在更新。这不会导致您的客户端重新加载。由于您只是导航到在浏览器中创建的端点,因此如果不刷新,您将看不到反射(reflect)的更改。

这并不是说以这种方式运行 nodemon 没有任何好处。如果您不这样做,则还需要关闭 Node 实例(ctrl-c),然后每次刷新页面之前重新运行它。否则,您仍然会运行旧版本的服务器,并且仍然会看到相同的内容。

最终,您将使用客户端应用程序中的 http 客户端来使用这些端点,这通常是在您利用热重载环境时。有一些选项here如果您想在此之前进行快速实时重新加载。

关于javascript - Nodemon 不重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55820413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com