Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics (2014) Building a Command Line Application Making a GET Request with http

Node js documentation http.get

Present documentation for of Node.js http.get and https.get is different then in this course, here is an example:

http.get('http://www.google.com/index.html', (res) => {
  console.log(`Got response: ${res.statusCode}`);
  // consume response body
  res.resume();
}).on('error', (e) => {
  console.log(`Got error: ${e.message}`);
});

I am pretty stuck at the moment, What are $ and => signs, how to use it? Please help.

rydavim
rydavim
18,813 Points

I've added some code formatting to your post. You can do this using the following markdown:

```language

your code here

```

2 Answers

jobbol
seal-mask
.a{fill-rule:evenodd;}techdegree
jobbol
Full Stack JavaScript Techdegree Student 16,610 Points

Arrow Functions

The => operator is called an Arrow Function. Think functions, but quicker to type, and doesn't change the value of this. They just added the arrow with the introduction of Javascript 6.

//arrow function
var sum = () => 1 + 2;

//same as regular function
var sum = function() {
    return 1 + 2;
};

Template Strings

The ${ } syntax refers to a template string. Also new. It lets you run code from within a string. It must be inside a string with backticks(`) instead of quotes(' or ").

//string concatenation
var name = 'Brendan';
console.log('Yo,' + name + '!');

//template strings
var name = 'Brendan';
console.log(`Yo, ${name}!`);
rydavim
rydavim
18,813 Points

If you want to use the documentation syntax Darko Gregurek, this is an excellent explanation by Josh Olsen. :)

Thank you very much for your help!

I got it, thank you very much, I understand syntax now.

rydavim
rydavim
18,813 Points

They use a bit of shorthand in the documentation that can be hard to follow. You can think of that code as being the same as the code below:

http.get('http://www.google.com/index.html', function(response) {
  console.log('Got response: ' + response.statusCode);
  // consume response body
  response.resume();
}).on('error', function(error) {
  console.log('Got error: ' + error.message);
});

Let me know if that's still confusing though, and we can work on whatever your current project is so you can see some practical examples. Happy coding! :)

Thank very much for your help!