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 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;

2 Answers

Sean Gibson
Sean Gibson
38,363 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,363 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.

Seth Foss
Seth Foss
7,097 Points

I was having the same issue in a Python Flask workspace. Turned out to be caused by running the web server on IP 127.0.0.1 - workspaces requires 0.0.0.0