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 Debug Node Applications with Visual Studio Code!
You have completed Debug Node Applications with Visual Studio Code!
Preview
There's more to debugging Node.js programs than logging values in your code. In general, console.log
can be problematic, but you can overcome those problems using the Visual Studio Code editor's built-in debugger.
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
[MUSIC]
0:00
Debugging is the process of identifying
and fixing defects in a program.
0:09
When you think about debugging one method
that might come to mind is writing
0:13
console.log statements to try to
identify what's gone wrong in your code.
0:17
The console.log method is native to Node
JS, where it prints to the terminal.
0:21
Similar to the way it prints to the web
browser's console when used in client side
0:25
JavaScript.
0:29
With console.log you can, for example,
take snapshots of variables at specific
0:30
moments in your program, which gives you
insight into where things are going wrong.
0:34
While console.log may be a tried,
and true, and
0:38
seemingly reliable approach to debugging.
0:41
It's not the most ideal or efficient way
to check the state of your application and
0:43
debug your program.
0:48
For example,
when building Node applications,
0:49
all HTTP requests get
logged to the console.
0:52
This generates a lot of
noise in the terminal,
0:54
which can make it difficult to locate the
values you're trying to log and evaluate.
0:57
And what if the log value is
exactly what you were expecting?
1:01
You have to stop your application,
1:04
then figure out where to write
another console.log statement.
1:06
This process can get unwieldy.
1:09
In addition, when u write a console.log
you are adding code to your application.
1:11
Because your program technically doesn't
require the console.log statement to
1:16
function.
1:20
And when you're done debugging,
1:20
you'll usually have to go back to your
program and remove all the log statements.
1:22
Not removing them means, you might commit
those log statements to version control.
1:26
Which can lead to
confusion later when you or
1:30
other developers working on
the project revisit the code.
1:32
In general,
console.log can be problematic.
1:35
But you can overcome those problems
by using proper debugging tools.
1:37
There are other more capable and
efficient ways to debug and node.
1:41
I'm Guil,
a JavaScript instructor here at Treehouse.
1:44
In this workshop, I'll teach you how
to debug node applications using
1:48
the Visual Studio Code
editors built in debugger.
1:51
There's more to debugging node programs
than just logging out values in your code.
1:54
VS code's reliable debugger provides
many useful features including a way
1:59
to pause the execution of a program
at specified points in the code.
2:04
This allows you to inspect the contents
of variables, and modify their values
2:08
while the program is running to
check how it affects the program.
2:12
You're able to execute or
run a program one line at a time.
2:15
That way you can see what's happening
inside your program as it runs line
2:19
by line.
2:23
And once you identify the problem,
you can quickly fix the defect and
2:23
test your fix until you've got your
program working the way you want it to.
2:27
You can do all these and
more directly in the VS Code editor.
2:31
The application we will use in this
workshop is an express application that
2:35
was generated using the express generator
command line tool and slightly modified.
2:40
This simple application called Reversify
takes any string from URL and reverses it.
2:44
And it provides a few examples.
2:50
Notice, that when I click on mali,
for instance,
2:51
the application shows that
blink reversed is ilam.
2:54
The original string, mali,
is missing from this text.
2:58
It's supposed to look like this.
3:01
I'm getting unexpected behavior,
but no doesn't see or
3:04
report any problems or
errors with the code.
3:08
This is the bug.
3:11
So in the next video,
3:12
will get set up to debug the application
to see where it's breaking.
3:13
Before you start, download
the project files for this workshop.
3:16
And make sure that you have
Visual Studio Code, and
3:19
no JS installed on your computer.
3:22
I've provided links in the teachers notes
with this video to help you get set up.
3:24
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