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

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 = '127.0.0.1';
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.