Update nodeJS file without stopping restart

1

Will there be a way to update a file and see the changes in real time?

example

  

I have a file server.js and I modify it.

How do I see the result without stopping the service and restart it with node server.js ?

    
asked by Merling Samuel Sobalvarro 16.02.2018 в 01:03
source

2 answers

5

You can use nodemon, which is a node daemon to run the server, so every time there are changes it will be updated without having to restart the server, install it:

npm install -g --save nodemon

then you run it:

nodemon server.js

and ready.

    
answered by 16.02.2018 / 01:57
source
1

As you have answered Lius Angel you can use nodemon, but so that you do not have to execute the order every time in the console, what you can do is include the start script in package.json. I'll explain with an example.

Package.json:

"name": "api-restful-ejemplo",
  "version": "1.0.0",
  "description": "API de ejemplo",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index.js",   <---- Si te fijas, esto ha sido incluido posrteriormente.
    "test": "echo \"Error: no test specified\" && exit 1"
  },

This way every time you make a save of your code, it will be updated. I hope I've been helpful. Greetings.

    
answered by 16.02.2018 в 13:50