Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 11,868 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.