Build a Submission Form - Lesson 4

Tell us what’s happening:

Test 2 of Lesson 4 always fails, and my attempts to output the server URL aren’t being detected properly. Hardcoding the desired output in the app.listen callback doesn’t work. Neither does using a middleware for it.

Your code so far

import express from 'express';
const app = express();

app.use('/', (req, res, next) => {
    console.log('from middleware');
    console.log(req.hostname);
    next();
})

const server = app.listen(3000, ()=>{
    const hostname = server.address().address;
    console.log('listening callback');
    console.log(hostname);
    if(["::", "0.0.0.0"].includes(hostname)){
        console.log("localhost");
    }
})

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-build-a-submission-form/64d7d73f8932c4087d7c08f4.md at main · freeCodeCamp/freeCodeCamp · GitHub

The lesson asks you to log the server’s URL. Your callback logs a hostname, but what else would you need in the address bar to visit your server? Think about the protocol and the port you passed to app.listen.

Keep that log inside the app.listen callback so it runs when the server starts.

I managed to get it working after using server.address() itself for the output instead of trying to deal with its properties.