Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Check out my solution for the first part of the challenge.
This video doesn't have any notes.
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
How did it go?
0:00
Great job if you got it and
0:01
it's okay if you didn't because
I'll share my solution with you.
0:02
First, we'll need to require the HTTPS
module so that we can use our get request.
0:06
We'll create a function named getDef that
takes a term from the command line to
0:11
search for
from the Merriam Webster Dictionary.
0:15
Now we'll create a request that
uses the dictionary API url,
0:20
including the term interpolated and
ending with the API key.
0:25
Now we'll take the response,
and every time data comes in,
0:31
we'll append the data to
an empty string named body.
0:36
Again, we'll use the .on method to do
this to handle event listening and
0:42
watching in node.
0:46
And we'll wait for
the end of the data using the end of it.
0:49
When all the data has been sent,
we'll use JSON parse to parse the data and
0:55
we'll use the console log
statement to print the data out.
1:00
The response returned is
in the form of an array.
1:05
Our definition is in the first array
item under a property name shortdef.
1:08
This is what we'll print
out to the screen.
1:14
We'll add some error handling to
watch out for errors on request,
1:18
and catch parsing errors.
1:22
Finally, we'll use argv
to access our arguments,
1:26
and call forEach on the command
line arguments entered.
1:30
We'll save.
1:35
Go back to the terminal,
we'll try node app.js imperative,
1:38
and we get the short definition
printed to the screen.
1:43
We can try adding another word.
1:49
And we get multiple definitions.
1:53
Great work following along.
1:56
You've created two command
line node applications.
1:59
And we've only scratched
the surface of what node can do.
2:01
With node, we can add open source code
from other developers to our projects,
2:05
build applications that scale,
work with powerful libraries.
2:10
And connect our front end
projects to databases.
2:13
There's so much more to learn.
2:17
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