Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed User Authentication With Express and Mongo!
You have completed User Authentication With Express and Mongo!
Preview
Nodemon is a great tool to use when developing an Express app. It lets you make changes to your JavaScript code and immediately see those changes in a browser, without having to manually stop and start the server.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Thus far I've been starting this app from
the command line by typing node app.js.
0:00
This tells the node process to run
the JavaScript and the app.js file.
0:07
But there are other ways to start up
this app, and one that's perfect for
0:11
rapid development cycle
where you're writing your app.
0:14
Another common way to start up
an express app is to add a start task
0:17
to the package.json file.
0:21
The start task can start
the Express app for you and
0:23
it can run commands with additional
arguments if you need them.
0:26
For example, the start task could start
up a server on a specific port and
0:29
also specify some settings for the server.
0:33
In fact in our package.json file,
you'll see there's already a start task.
0:36
It runs the command node ./app.
0:41
./ means look in the current directory for
a file named app.js.
0:44
With node you don't have to include
the .js extension when referencing
0:49
a JavaScript file.
0:54
To use this command, you go to
the terminal and just type npm start.
0:55
First, let me stop the currently
running express app and
1:00
then I just type npm start.
1:05
And it's the same thing,
we've started up the server.
1:07
Finally, there's one other
way to start our app and
1:10
it's a great method to
use during development.
1:12
It's called nodemon, and
it's a helpful node.js application.
1:14
It starts up your app and
1:19
refreshes it each time you make
a change to a JavaScript file.
1:20
For example,
when you start up your app with nodemon,
1:24
you could edit the routes file or
the app.js file.
1:27
When you save the changes, nodemon
stops the server then restarts it, so
1:30
your changes take effect immediately.
1:33
Nodemon is a wrapper for node,
it basically runs node but
1:36
includes a watch command that watches for
changes to the application code and
1:39
then restarts the server
when changes are made.
1:44
Okay, I'll go back and
stop our application.
1:47
To install nodemon globally so you can
use it in other applications type npm
1:51
install -g nodemon.
1:57
You can also just install it locally for
2:04
this project by typing in npm
install --save-dev nodemon.
2:07
Once installed, you can start the app with
nodemon, it's as simple as typing nodemon.
2:13
This command uses nodemon to run
the start task in the package.json file.
2:21
All right let's check out the application
again at local host 3000.
2:26
If I make a simple change to
the route.js file in my text editor,
2:31
nodemon will stop and
then restart my application.
2:36
Let me show you how it works.
2:39
I'll open the index.js file and
change this message here to NODEMON.
2:41
When I save the file and
go back to the terminal,
2:49
you'll notice that nodemon stopped and
then restarted application.
2:52
I can prove that by going and
checking out our application,
2:57
clicking on the sign up route and
notice that we've updated our application.
3:00
If you haven't yet installed nodemon,
I'd recommend installing it.
3:06
It's a big help while
working on Express apps and
3:09
I'll be using it in the rest of
this course to spin up our app.
3:12
Okay, it's time to dive into
the Pug templating language and
3:15
build a registration form.
3:18
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up