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!

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


Jennifer Boyle
Jennifer Boyle
6,800 Points

Anyone fix the preview issue?

I am still unable to preview the app.js in the browser. I get the following error:

"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."

My app.js code is:

var router = require('./router.js');
//Problem: We need a simple way to look at a user's badge count and JavaScript points from a web browser
//Solution: use Node.js to perform the profile look ups and serve our templates via HTTP

//Create a web server
var http = require('http');
http.createServer(function(request, response){
  router.home(request, response);
  router.user(request, response);
console.log('Server running at http://<workspace-url>/');

My router.js code is:

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

//Handle the HTTP route for GET /:username i.e. /chalkers
function user(request, response){
  //if url == "/..."
  var username = request.url.replace("/", "");
  if (username.length > 0){   
    //get JSON from Treehouse
      //on "end"
        //show profile
      //on "error"
        //show error

I've tried all ports available, I've even switched from http to https and back again, nothing. When I run my code in the console for the Node portion, I get the exact same results Andrew does for his code. Is there a way to fix this issue so that I can preview what I'm doing?

Jennifer Boyle
Jennifer Boyle
6,800 Points

I forgot to mention this is the "Build a Simple Dynamic Site With Node.js" portion of the JavaScript track.

1 Answer

Jennifer Boyle
Jennifer Boyle
6,800 Points

Never mind, I restarted my whole computer and it sorted itself out...