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 Simple Server in Node.js Creating a Simple Server

Server is unavailable

I have tried previewing the workspace several times, I had the code working but now it keeps throwing an error. I changed all reference to http to https no such luck.

Here is my code

//problem: We need a simple way to look at a users badge count and javascript points from a web browser

//Solution:Use node.js to perform the profile lookups and serve our templates via http


//Create a web server
var https=require('https');
https.createServer(function (request,response){
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');
}).listen(3000);
console.log('Server running at https://<woorkspace-url>/');

//Handle http route GET / and POST / i.e. Home
  //if url == "/" && GET
  //show search
//if url == "/" && POST
  //redirect to /:username

//Handle HTTP route GET /:username i.e. /aaronendsley
//if url =="/..."
//get json from treehouse
//on "end"
//show profile
//on "error"
//show error

//function that handles the reading of files and merge in values
//read from file and get a string 
//merge values in to string
Nicholas Lee
Nicholas Lee
12,474 Points

Did you ever get it to work? I am having the same issue.

8 Answers

Nicholas Lee
Nicholas Lee
12,474 Points

Aaron, I got it to work. The problem for me was that I was trying to use the https. Before, I changed all http to https in the profile.js file and app.js because teamtreehouse recently switched over to that protocol. However, in this stage of the app that is not needed. We're creating our server and just using the http protocol. I got it to work by reverting back to HTTP. Not sure how this will work when we need to access the api though.

It's also possible that some the http.createServer() method is not different not the same for https. Not sue though.

Feel free to add or correct anything I have said.

Thank you sir that makes sense, I thought it might be that because workspaces doesn't register as an https, when you copy and paste a workspace address it shows up as an http. Thank you, you are awesome! I never thought to look at the profile js.

Maria Campbell
Maria Campbell
8,641 Points

This is really not a consistent project. Too bad because I do like Andrew's courses, but Treehouse should have been on top of it (not Andrew) about making sure to update any courses that were impacted by the switch from http to https. I personally do not use workspaces but terminal. I'll see if http works for me in this step. Hope so!

Marc-Oliver Gern
Marc-Oliver Gern
8,747 Points

The code snippet on nodejs.org changed slightly and I got it to work with:

const http = require('http');

//const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((request, response) => {
  response.statusCode = 200;
  response.setHeader('Content-Type', 'text/plain');
  response.end('Hello World\n');
});

server.listen(port, () => {
  console.log(`Server running at http://${port}/`);
});
Elina Nenonen
Elina Nenonen
15,310 Points

Nice, this worked for me too. Thanks!

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

I also have the same issue and am unable to get the page to appear in the browser after I start the server in the console. I'm using https and it runs in the console. If I change it to http, I get a bunch of errors. ''' var https = require('https'); https.createServer(function (request, response){ homeRoute(request, response); }).listen(8080); console.log('Server running at http://<workspace-url>/');

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 } '''

Here is the error 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.

Any help would be appreciated.

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Michael, I'm having the exact same problem with the workspace being unavailable. Did you find a solution to the problem? Any advice would be greatly appreciated.

Wilson Usman
Wilson Usman
35,206 Points

How come my local server is running, but it just repeats the date?

For example:

Wed Jan 06 2016 23:34:40 GMT-0600 (CST) Wed Jan 06 2016 23:34:40 GMT-0600 (CST) Wed Jan 06 2016 23:34:40 GMT-0600 (CST) Wed Jan 06 2016 23:34:40 GMT-0600 (CST)

Erik Nuber
Erik Nuber
20,629 Points

Without seeing your code, the most likely reason is that there is no response.end statement.

lionelsurmont
lionelsurmont
7,092 Points

Ah! It finally worked when I installed Node.js on my computer. Should have been clearer than that...

By following the video exactly. I got the server going in gitBash and then typed "localhost:3000" in the browser window when I ran it from my text editor Notepad++. If you type in "http://localhost:3000", it won't work.