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

Clint Oka
Clint Oka
5,768 Points

Can't get my port to show Hello World...

Here's my code

const http = require('http');

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

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');

server.listen(() => {
  console.log(`Server running at http://<workspace>/`);

this is the error I get

This site can’t be reachedlocalhost refused to connect. Try:

Checking the connection Checking the proxy and the firewall ERR_CONNECTION_REFUSED

1 Answer

Clint Oka
Clint Oka
5,768 Points

Problem solved. I didn't run the app.js in the terminal. Once I did node app.js in the terminal and got the server running. I can see Hello World.

Hi Clint, I did my code like yours but I still can't seem to see the Hello World. How did you solve yours? I dont quite understand your solution from your comment above. PS: I am using the workspace btw.