Reputation: 103
I am learning about NodeJS and I am using simple code for tests. My problem is I must restart server for each change I realize to my code but I see videos where another developers to make changes on html file and they must not restart server. What I do incorrect? Thank you!
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]
Upvotes: 3
Views: 839
Reputation: 155
In order to get your server to automatically update, you have to install the right package. For example the npm package nodemon. npm install -g nodemon(or if yarn, use that command) will install the package globally so you can have your servers autorestart. Instead of the command "node app" you would then use the command "nodemon app". Hope this answers your question!
Upvotes: 3