-2

I couldnt find answer for this question.So that..for example

app.js

 //express require 

    app.get("/test",function(req,res) {
          res.send("hello world");
   });

   app.listen(3000)

when we work it via "node app.js".. We see "hello world" we requested http://ip:3000/test on browser . but when we changed file, for example

//express require 

    app.get("/test",function(req,res) {
          res.send("hello world 2");
   });

   app.listen(3000);

when we refreshed to browser.. we still see "hello world"...because we does not "node app.js command"

well!! but why????

when we worked "node app.js" command on console..what does node work for this?

Spartan Troy
  • 949
  • 2
  • 9
  • 13
  • 1
    You are using ExpressJS if i am not wrong and you need to restart the server to see the changes, though you can use grunt/gulp to watch files and reload if something change. FYI - If you serve any static html files(res.sendFile('xyz.html') ) and made changes in those files you don't need to restart the server then – swapnesh Nov 24 '16 at 07:09
  • check this: http://stackoverflow.com/questions/1972242/auto-reload-of-files-in-node-js – Mohsen ZareZardeyni Nov 24 '16 at 07:15
  • Once node.js loads your server code, it does not ever reload the code again, even if you have changed it. You have to shut-down the server, exiting the node.js process and then restart your node.js app and it will then load the newly changed code. This can be different for HTML and JS that is served to the browser. It is possible for your web server to see the newly changed files and send the newest files to the browser. But that's not code that is running in node.js, just code it is sending to the browser. – jfriend00 Nov 24 '16 at 08:12

1 Answers1

0

Actually node doesn't refreshes the content until you restart the server. So, just restart the server after changing the content.

You can use --watch to watch for the changes automatically restart the server if content is changed.

Atul Sharma
  • 9,397
  • 10
  • 38
  • 65