Using localhost for Back End Development and APIs / Basic Node and Express

Tell us what’s happening:
Describe your issue in detail here.

Hello,
I didn’t have any trouble completing the challenges locally in the “Managing Packages with NPM” section, but in this section, nothing seems to be working. For instance, in this first challenge, “Meet the Node console,” I can see “Hello World” being printed to the console, but the freeCodeCamp web site doesn’t seem to be able to detect it.

This is what I see in the macOS Terminal window:

Js-MacBook-Pro:boilerplate-express jasu62$ npm start

> fcc-learn-node-with-express@0.1.0 start
> node server.js

Hello World
Node is listening on port 3000...

And this is what the FCC page shows when I use https://localhost:3000 :

// running tests
"Hello World" should be in the console
// tests completed

I don’t see any other messages in the console window, and the test fails. I’m likely overlooking some totally obvious setup steps, so please let me know!

Your code so far

var express = require('express');
var app = express();

// 1. Meet the Node console
console.log("Hello World");

/*
// 2. Start a Working Express Server
app.get("/", function(req, res) {
  res.send("Hello Express");
});
*/

/*
// 3. Serve an HTML File
app.get("/", function(req, res) {
  res.sendFile(__dirname + "/views/index.html");
});
*/


module.exports = app;

You can see here that I tried the second and third exercises, too, but to no avail. The second exercise directs us to put our code between the lines already included in the file, which are, in this code, the first two lines and the very last one, so I went back and moved my console.log() statement between them.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Meet the Node console

Link to the challenge:

If you’re running your code locally, an external website (like freeCodeCamp) can’t see it. Submitting a localhost URL isn’t going to pass any tests.

There are tools like ngrok for creating a tunnel to access your local server, or you can run your code on a cloud service like Replit :slight_smile:

Is it absolutely the case that I cannot run code locally for these exercises? I ask because in the previous section, I was able to do so. I got the directions here:

Not only that, but the instructions in the first exercise for this section that I’m having trouble with, which my first post links to, explicitly state the following:

Working on these challenges will involve you writing your code using one of the following methods:

  • Clone this GitHub repo and complete these challenges locally.
  • Use our Replit starter project to complete these challenges.
  • Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo.

So I just want to be absolutely sure that, in spite of what these instructions say as well as the fact that I was able to do it locally in the last section, this section actually does not work with locally-run code.

That’s strange. I tested all my Back End Development and APIs Projects locally and they would pass the tests.
Only later would I use Replit for it to be publicly accessible.

Edit: @nhcarrigan Initially I thought that this might be a security concern but then I remembered that all boilerplates come with CORS. Isn’t that its purpose? For the fcc browser to be able to access our localhost?

Hi @jasu62 !

Welcome to the forum!

Make sure you are using http not https

Correct localhost link

http://localhost:3000/

Hope that helps!

@jwilkins.oboe Is cors the reason why fcc can access the localhost? after reading this and this it seems to be the case. Not really sure tough

I believe so but more experienced devs on the forum can probably give you a much better answer than me :grinning:

@jwilkins.oboe just did a quick test and removed cors from one of my projects. As expected the test fails because fcc can’t see my localhost.
Because accidental/unintentional cross-origin resource sharing is a possible security concern I think :grinning:

Thank you so much! That was the issue! I just passed the first three exercises.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.