为什么没有重启javascript服务器我的html内容不会更新?

问题描述 投票:3回答:1

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

的package.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"
  }
}

app.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);

index.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]
html node.js updating
1个回答
1
投票

为了让您的服务器自动更新,您必须安装正确的软件包。例如npm包nodemon。 npm install -g nodemon(或者如果是yarn,请使用该命令)将全局安装软件包,以便您可以让服务器自动重启。而不是命令“节点应用程序”,然后您将使用命令“nodemon app”。希望这能回答你的问题!

© www.soinside.com 2019 - 2024. All rights reserved.