Reputation: 33
I am new in nodejs ,every time I create a project I have to restart the server after modifiying html files also when using twig,jade or ejs templates engines. Any ideas on how make the changes show up on browser without restarting the server everytime.
this is server.js:
var express=require('express');
var bodyParser=require('body-parser');
var path=require('path');
var twig=require('twig');
var app=express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
app.use(express.static(path.join(__dirname,'public')));
app.set('view engine','twig');
app.set('twig options',{strict_variables:false});
app.set('views',path.join(__dirname,'views'));
app.get('/',function(req,res){
res.render('index.twig',{message:'test'});
});
app.listen(3000,function(){
console.log('Server started and listening on port 3000 ... ')
});
I use twig as view engine
views/index.twig :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
{{ message }}
</body>
</html>
I use nodemon also I tried with supervisor ,same nothing changed in both
Upvotes: 0
Views: 1024
Reputation: 41
To fix that you can use nodemon like that
nodemon -e .js,.twig app.js
You can also create nodemon.json in your root folder and add this config :
{ "ext": "js,twig,mjs,json" }
Upvotes: 4
Reputation: 20158
Use nodemon npm module and reload your project when you have made changes.
Install nodemon globally
$ npm install -g nodemon
Install nodemon as a developement dependency
$ npm install --save-dev nodemon
$ cd [project path] // ex: myapp
$ nodemon [your node app] // nodemon ./server.js
Upvotes: 0