Finding Help as a Node.js Developer7:15 with Andrew Chalkley
Being a developer in any environment requires you to know what tools are at our disposal to help us in our endeavors building applications.
If you're new to ECMAScript 6 syntax you might also want to check out Introducing ES2015.
If you're unfamiliar about HTTP and want to learn more about it in general check out HTTP Basics.
Being a developer in any environment requires you to understand the tools we 0:00 have for building any given application. 0:04 What do we do when we get stuck, where can we look for possible APIs that we can use? 0:07 Here's a few tips. 0:11 If you get stuck in this course, or even in your own projects, you can ask for 0:13 help in the Treehouse Community Forum. 0:17 Your fellow students can give you hints and suggestions. 0:20 In fact, students are rewarded for participating in the community, and 0:22 by giving the best answers. 0:27 Be sure to remember to embed your code, or link to the source code of your project. 0:29 Got an error, and not having much luck in the community? 0:33 There's a chance someone else has had the same issue as you. 0:36 How do you find them? 0:39 Open up your favorite search engine, and 0:41 paste in the most relevant part of the error message. 0:43 There's countless numbers of blog post, sites, 0:46 forums, newsgroups, where people post their problems, and how they solve them. 0:48 But probably the most important place you can get see what's possible with any given 0:53 language, framework, or platform is, by going to its official documentation. 0:57 In our case, it will be the node.js documentation site. 1:02 Let's take a quick look now. 1:06 Node.js is official website is, node.js.org. 1:09 Click on docs in the navigation, in of the languages and frameworks. 1:13 It may say documentation or API. 1:18 Generally, these terms are interchangeable. 1:21 API stands for application programming interface. 1:23 The documentation explains the API, or how you interface with 1:28 the objects in the language, environment, or framework that you're working in. 1:32 In other words, the API is the objects and 1:38 methods that you can use in any given environment. 1:41 In the browser, 1:44 the API is called the document object model to interface with web pages. 1:45 With node.js, the API is what you interface with the file system, 1:50 or other APIs like making HTTP requests. 1:55 Don't worry if the website looks different from how it looks on your screen. 1:59 Websites are always being updated. 2:03 As a developer, we must be adaptive to our ever changing surroundings. 2:05 Let's click on the API closest to the version of node that you've got installed, 2:09 or is in Workspaces. 2:15 Looking in the Table of Contents, there's a link to about the docs. 2:18 I want to point out the section at the bottom called the Stability Index. 2:23 Zero means you shouldn't be using this anymore, 2:28 because it's deprecated, one is experimental, and 2:31 is something that many come in the future, but it could be removed. 2:35 So you've been warned. 2:39 Whilst indexes two and three stable unlocked, 2:42 it shouldn't change, unless something serious happens. 2:46 So, you say if using these in your applications, as a developer, 2:50 you'll be making difficult decisions all of the time. 2:54 And choosing what API you should use of or another is one of those times. 2:57 But in general, the rule of thumb is to stick to stable unlocked APIs. 3:01 Now let's go back to the API docs, and 3:07 take a look at some of the things that you can do with node.js. 3:09 Listed in the table of contents are all the APIs that 3:14 come out of the box with node.js. 3:17 All should include their own stability index. 3:19 Some of the most common APIs that you'll use are the console, 3:23 which is the way to output strings to the console. 3:26 File system, these are where the APIs to read and write files are found. 3:30 And HTTP and HTTPS, for creating web servers, or 3:36 going out to the Internet to retrieve information. 3:41 Let's take a look at one example in HTTPS. 3:44 When we click through, there's a table of contents. 3:48 This is where you can skim through the possible objects, methods, 3:52 and properties related to the HTTPS web requests and responses. 3:57 Let's take a look at https.get. 4:02 The first line of code is including the HTTPS methods to 4:06 handle what requests to HTTPS, secure HTTP service. 4:10 The https.get method has a string of a URL 4:15 pointing to the secure sites encrypted.google.com. 4:20 The second argument is an arrow function. 4:26 I call back. 4:30 If you're unfamiliar with this syntax, see the teacher's notes for 4:31 some material to watch. 4:34 In our analogy before, the request is us sending out an invoice. 4:37 The call back is the client sending the payment to us. 4:42 Google's server is sending a response to us. 4:47 Res is short for response. 4:50 Because node.js is built with the non-blocking model in mind, 4:52 the application can still be doing other things, while we write for the response. 4:57 Using callbacks is a common pattern you'll see in building node.js applications. 5:03 A lot of built in node.js APIs require callback functions. 5:08 A callback function gets executed when the program is finished a particular task, 5:14 or an event has occurred. 5:19 If you build Ajax applications before, you don't have to halt your job script 5:21 program while you wait for the response from the server. 5:26 You give it a callback to run once the data has been downloaded. 5:30 If you've ever interacted with user events like mouse clicks or keyboard presses, 5:34 you don't halt the program from running until the event occurs. 5:38 You give it a callback to be executed when the event occurs. 5:42 In node.js, you can do the same thing, you provide a callback for System Events. 5:47 So, in this example, 5:53 the response has a system event called data associated with it. 5:56 Then this callback prints out a piece of data. 6:02 System events are triggered by the computer, not a user interaction. 6:06 Process.stdout.write is just using console.log to print out information. 6:10 This bit of code here responds to an error event on the request object. 6:18 When you see on method being called on an object, it's responding to an event. 6:23 You'll see this a lot in node.js. 6:29 These lines tell you the response is status code, 6:32 whether the request was successful or not. 6:34 And then any special metadata called headers was sent from the server. 6:38 If you're new to HTTP requests, 6:44 I've included some information in the teachers notes about HTTP. 6:46 However, we'll cover what we need in this course as we go forward. 6:50 As a developer, 6:55 being able to ask specific questions, short examples of your code, and 6:56 synthesize the information from a number of sources is an absolute required skill. 7:01 It may feel daunting at first, but it gets better, I promise. 7:06 It takes practice, but for 7:09 now, I'll be here to help you build these command line applications together. 7:11
You need to sign up for Treehouse in order to download course files.Sign up