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 Build a Simple Dynamic Site with Node.js Handling Routes in Node.js User Route

Christopher Johnson
Christopher Johnson
12,829 Points

Syntax Issue

This is pulled straight from Nodejs.org and I'm having issues with:

  1. 'router.home' - home is highlighted orange; yet, 'router.user' - user remains green.

  2. If I hit enter to create a new line from the ';' after 'const server', it automatically indents, which tells me there is a syntax error. I'm not sure the reasoning behind using => in this application.

  3. "Server running at http://${hostname}:${port}/'" - I understand what's suppose to happen, but it's not filling in this information. It intentionally came with a ' ' instead of a " ' ."

var router = require('./router.js');
//Problem: We need a simple way to look at user's badge count and JavaScript point from a web browser
//Solution: Use Node.js to perform the profile look ups and serve our template via HTTPS

//Create a web server
const https = require('https');

const hostname = '127.0.0.1';
const port = 3000;

const server = https.createServer((request, response) => {
  router.home(request, response);
  router.user(request, response);
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Ran ShemTov
Ran ShemTov
14,148 Points

Try checking if any of the backslashes are giving you the error on the console.log statement

1 Answer

You didn't mention what you had pasted this content into that was giving you errors, but my setup detects no problems at all. The arrow syntax is the new ES6 arrow functions notation. As to your last point, that's a template string, which is surrounded with backticks instead of quotes.