gpt4 book ai didi

html - 为什么我的 html 内容在不重启 javascript 服务器的情况下无法更新?

转载 作者:搜寻专家 更新时间:2023-10-31 23:57:13 25 4
gpt4 key购买 nike

我正在学习 NodeJS,我正在使用简单的代码进行测试。我的问题是我必须为我意识到对我的代码的每次更改重新启动服务器,但我看到其他开发人员对 html 文件进行更改的视频,他们不能重新启动服务器。我做错了什么?谢谢!

包.json

{
"name": "xxxxxxx",
"version": "1.0.0",
"description": "xxxxxx",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "xxxxxxxx",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"jade": "^1.11.0",
"pug": "^2.0.3"
}
}

应用程序.js

const express = require('express');
var app = express();
app.set('view engine','pug');
let personas = [
{
id: 1,
nombre: 'wwww'
},
{
id: 2,
nombre: 'qqqq'
},
{
id: 3,
nombre: 'ssss'
}
];
app.get('/', function(req,res) {
res.render('index',{hola:"Hola wqw",titulo:'pug',mensaje:'sdasd!!',personas:personas});
//res.send('Hola mundo');
});
app.listen(8080);

索引.pug

html
head
title= titulo
link(href='https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css',rel='stylesheet')
body
div.container
h1= mensaje
table.table.table-striped
for persona in personas
tr
td= persona.id
td
a(href='/persona/' + persona.id) #{persona.nombre}
- //Esto se ejecuta en el servidor
- var arreglo = [1,2,3,4,5];
- for (var i = 0; i < arreglo.length; i++)
p= arreglo[i]
p!= "<h1>Se ejecuta como HTML</h1>"
p Hola #{mensaje}
p.
Hola haz click en #[a(href="https://www.google.com") este link]

最佳答案

为了让您的服务器自动更新,您必须安装正确的软件包。例如 npm 包 nodemon。npm install -g nodemon(或者如果是 yarn,则使用该命令)将全局安装包,这样您就可以让您的服务器自动重启。然后您将使用命令“nodemon app”代替命令“node app”。希望这能回答您的问题!

关于html - 为什么我的 html 内容在不重启 javascript 服务器的情况下无法更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52195933/

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