Make Express server refresh automatically

express
nodejs

#1

Hi,
I am an experienced server side developer and JS developer, but new to node and express.

Why must I run bin/www again in order to see changes? isnt node like PHP? allowing to change the code while running?

Thanks.


#2

Hi, Avi.

What do you mean by running bin/www again?
If you run the file (the .html files) itself I believe it will run Apache and act like a simple ftp server / static server (PHP works easily like that).

But when you’re using Node.js, you need to run the initial app.js(or whatever that file is called for you) file, in which you may set using Express the folder bin/www static. Static folders set does not need you to re-run the node program. But if you change the app.js file itself I believe you’ll need to re-run it.

Cheers,
-Joe Tannoury


#3

Hello and thanks.
According to this tutorial, when I want to run the node server i need to run in the shell: bin/www so the node server will run.

If I do so, when I change the index.js for exanple, I dont see the changes unless i run in the shell bin/www again

Thanks


#4

Oh I get it now. Running “bin/www” runs “bin/www/index.js” of course.

Run index.js in debugger mode, that way you’ll see the changes live after saving the file.

Follow the tutorial page till the end on how to set up a “CREATING A RUN CONFIGURATION”. Don’t forget to set the debugging to true.

Cheers,
-Joe Tannoury


#5

So, I have created the run configuration, its event entering to debug.
But the changes in the file index.js or users.js are not appearing till I restart.
Thanks


#6

Hi Avi,

Right. Node will not automatically restart the server when you change code. However, there are utilities that reload the server on file changes, like https://github.com/remy/nodemon etc.

Regards,
​Mutahhir


#7

@mutahhir, So what JoeTann wrote is not correct? Wasnt what he says suppose to show changes in the browser?
Thanks


#8

@Avi only the static files automatically changes, not the node app itself. My mistake.


#9

I see, what is the shell command to reload the files into node? thanks


#10

There is no shell command but you can use https://github.com/remy/nodemon to make it auto restart.


#11

Like everyone else is saying Nodemon is my favorite tool out there for accomplishing this exact thing. Easy to use and has some good features(including support for coffeescript)