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 Home Route

Michael Randall
PLUS
Michael Randall
Courses Plus Student 10,643 Points

Workspace Unavailable on Create Web Server Node.js

I keep getting the message: "Workspace Unavailable - This is a preview link for a Treehouse Workspace that is not currently active. If you are the workspace owner, you can launch it again via the Treehouse site."

I've followed the instructions on the page and started the server in the console, then when I select view port 8080, it get the message from above. Here is my current code:

var https = require('https');
https.createServer(function (request, response){
  homeRoute(request, response);
}).listen(8080);
console.log('Server running at http://<workspace-url>/');

//2. Handle HTTP route GET / and POST / i.e. Home
function homeRoute(request, response){
  //if url == "/" && GET
  if(request.url === "/"){
    //show search
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.write("Header\n");
    response.write("Search\n");
    response.write('Footer\n');
  }
  //if url == "/" && POST
    //redirect to /:username
}

All of the other files are the same from the exercise. Are there any recommendations to get this working in the browser?

4 Answers

Try changing your code to use http instead of https:

var http = require('http');
http.createServer(function (request, response){
  homeRoute(request, response);
}).listen(8080);
console.log('Server running at http://<workspace-url>/');

//2. Handle HTTP route GET / and POST / i.e. Home
function homeRoute(request, response){
  //if url == "/" && GET
  if(request.url === "/"){
    //show search
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.write("Header\n");
    response.write("Search\n");
    response.write('Footer\n');
  }
  //if url == "/" && POST
    //redirect to /:username
}

They are in fact completely different modules...

I copied and pasted this code into my workspaces and it still doesn't work. I get the same "Workspace Unavailable" screen error.

i am having same issue says the server is not found . can any one help me

Hi, i had the same issue but figured it out, but I still have a question regarding this.when creating the server what stops the https module from working and not the htttp module. Is it the additional server protocols that are associated with https? What additional steps would you need to make the https module work on the workspace listening ports.

How did you figure it out?

I am still having issues with it not loading in the browser. Do I need to do something with the html file?