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

Martin Coutts
Martin Coutts
18,154 Points

When I type in username, eg. add /chalkers to URL then it comes up workspace unavailable

As said in the title I have followed the video but when I try to add a username my code does not act the same way. I have a feeling it has something to do with the line response.write(username - "\n");

in the Get username block //Handle HTTP route GET / username i.e /chalkers function user (request, response) { //if URL == "/....." var username = request.url.replace("/", ""); if (username.length > 0) { response.statusCode = 200; response.setHeader('Content-Type', 'text/plain'); response.write("Header\n"); response.write(username - "\n"); response.end('Footer\n'); } }

On the video the dash symbol in the response.write is blue but on my programme it is yellow so I'm wondering if it is a special character that I just can't make out on the video.

Jamie Carter
seal-mask
.a{fill-rule:evenodd;}techdegree
Jamie Carter
Front End Web Development Techdegree Student 12,096 Points

Check the video note section as they mention something you need to change to make this ork with their updated API if i remember correctly

2 Answers

Martin Coutts
Martin Coutts
18,154 Points

I had a look, it just has links to the different documentations, I had a look through the response.write link but couldn't see anything specific to this issue.

Instead of response.write(username - "\n");, try response.write(username + "\n");. The + operator concatenates two strings, so "Hello" + " world" becomes "Hello world", and username + "\n" becomes the value of the variable username followed by a line break.