01 - Nodemon Intro
In this module, we'll set up Nodemon for allowing us to more easily make changes to our server code.
Description
When you make a change to code on the client side, you just have to refresh the web page to see the effect of that change. With a server, however, it gets a little more complicated. Any changes that you make won't take effect until you stop and restart the server. When you're testing routes or endpoints and making minute changes over and over, that constant stop/start routine can get kind of ridiculous. Fortunately, we have a tool that will automatically restart your server every time you save a file: Nodemon.
Setup
In any directory, run
npm install -g nodemon
. This installs Nodemon globally on your machine. Note to Mac users: use sudo:sudo npm install -g nodemon
Go into the server directory (where the
package.json
file is visible) runnpm install --save-dev nodemon
. This saves Nodemon to yourdevDependencies
inpackage.json
.Still in the server directory, run
nodemon app.js
. This should start the server up. You should see this:The app is now running. You can stop the app with
ctrl + c
.Practice running the app with Nodemon by starting it back up with the command. You can push up arrow while in your terminal to get it back quickly.
With the server running and with Nodemon started, change the console.log statement in
app.js
to a new phrase. Try using this:app.listen(3000, function(){ console.log('Hey man!!!') });
Press save.
nodemon
should fire back up, and you should see the newconsole.log()
statement in your terminal.
Last updated