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 Creating a Basic Template Engine in Node.js Reading from Files

Gillian Nieh
Gillian Nieh
5,709 Points

Workspace Unavailable

I am having trouble loading the code in my browser. Every time I click to view in Port 3000, I receive 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 have checked my code, but I will embed my router.js file here. Sometimes when I try loading the file, I get an error, but not this time.

var Profile = require("./profile.js");
var renderer = require("./renderer.js");

//Handle HTTP route GET / and POST / i.e. Home
function home(request, response) {
  //if url == '/' && GET
  if(request.url === '/') {
    //show search
    response.writeHead(200, {"Content-Type": "text/plain"});
    renderer.view("header", {}, response);
    renderer.view("search", {}, response);
    renderer.view("footer", {}, response);
  }
  //if url == '/' && POST
    //redirect to /:username
}

//Handle HTTP route GET /:username i.e. /gilliannieh
function user(request, response) {
  //if url == '/...'
  var username = request.url.replace('/', '')
  if(username.length > 0) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    renderer.view("header", {}, response);


    //get JSON from treehouse
    var studentProfile = new Profile(username);
      //on "end"
      studentProfile.on("end", function(profileJSON) {
        //show profile
        //store the values that we need
        var values = {
          avatarUrl: profileJSON.gravatar_url,
          username: profileJSON.profile_name,
          badges: profileJSON.badges.length,
          javascript: profileJSON.points.JavaScript
        }
        //simple response
        renderer.view("profile", values, response);
        renderer.view("footer", {}, response);
      });


      //on "error"
      studentProfile.on("error", function(error){
        //show error
        renderer.view("error", {errorMessage: error.message}, response);
        renderer.view("search", {}, response);
        renderer.view("footer", {}, response);
      });
  }
}

module.exports.home = home;
module.exports.user = user;

1 Answer

Sean Gibson
Sean Gibson
38,358 Points

Same problem. Was working fine for a long time then all of a sudden. I tried Ctrl+C to kill the server, closing and reopening workspaces, logging out and logging in and various combinations thereof. Suddenly unable to continue....

Sean Gibson
Sean Gibson
38,358 Points

Maybe this helps: in my case it was because there was a typo in one of the files. If the code can't execute properly it seems that maybe it will cause the Workspace Unavailable page to appear, even though that may not necessarily be the case. Check your console to see if any errors appear after attempting to preview. To fix my problem, I simply deleted all my JS code, downloaded the final versions of the files from the Download section of the course, and copied and pasted Treehouse's code into my workspaces and it worked. So, it would seem I had some sort of typo somewhere.