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

Alex Lumierre
Alex Lumierre
11,010 Points

I cannot preview my web from workspace.

I am currently learning node.js, however I cannot preview my workspace (i.e. there is a lot of port option there). Regarding this, which port should I use? How to fix the workspace?

3 Answers

So first up, because this is a Node app (or Node HTTP Server), you need to make sure the server is running first.

Andrew says the following:

So, if we do show console and then node app.js, we can see the server's running at the workspace URL, and when we go to port 3000, it goes hello world.

Make sure that the node app.js is run in the console first, and use port 3000 for the preview.

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Iain,

I have got my server running in the console. I'm using port 3000. When I go to preview the workspace, it says it's unavailable. Do you have any advice on what the problem might be?

Hi Gabriel Ward, can you please share a Snapshot of your Workspace so we can see the code?

Same problem!

Finally, it worked for me. Here is my initial code (in app.js):

app.js
var http = require('http');
http.createServer(function (request, response) {
  response.writeHead(200, { 'Content-Type': 'text/plain' });
  response.end('Hello World\n');
}).listen(3000);
console.log("server running");