Replit and FreeCodeCamp compatibility

I was using Replit to progress with Basic Node Challenges, sadly Replit changed it’s settings as far as I know. Therefore, MANY features don’t work anymore or aren’t accepted from FCC validator.

I would love to know some alternative or a way to keep doing these challenges and keep learning. Right now I’ve spent 2hours and haven’t found an alternative site that FCC site likes.

It doesn’t accept .env files for example, and doesn’t accept the new version of it you can find on Replit. Doesn’t recognize the challenge “Implement a Root-Level Request Logger Middleware” when everything I’ve done seems fine

Your project link

solution: boilerplate-express - Replit

Challenge: Serve JSON on a Specific Route

Link to the challenge:

The challenge thattalks about env files specifically mentions using the Secrets tab.

That’s usually an indication of a small issue in your code.

I’ve passed these challenges using Repl.it, so they should work fine.

I’ve passed it in the secret tab. Tried everything and posted my solution also
Capture

s
the code I used for the root level request logger middleware

It’s better to post actual code instead of a picture.


app.get("/", (req, res)=> {
  res.sendFile(absolutePath)
});

What is this? It’s not part of the instructions? Edit: oh, New challenge was added to this

My solution is passing fine, so it’s a matter of finding what you did differently.

yeah sorry I’ll post the code directly from now on

app.get("/json", (req, res)=> {
  res.json({"message": process.env.MESSAGE_STYLE == "uppercase" ? "HELLO JSON" : "Hello json"})
});

That’s what I used, also in the secret tab as key MESSAGE_STYLE and as value: uppercase

I’d start adding console.log statements inside of all of your callback functions to see what’s happening. It’s not immediately obvious to me from seeing your code what is happening.

Inside of all my callbacks is code like

    console.log("/json request");
    console.log("  message: " + message);
    res.json({ "message": message });

That then shows up in the console as the app runs. That let’s you watch the behavior of the test suite.

Not sure if it matters, but my root level request is last in my app.

/json request
Error: Can't set headers after they are sent.
    at SendStream.headersAlreadySent (/home/runner/boilerplate-express-1/node_modules/send/index.js:386:13)
    at SendStream.send (/home/runner/boilerplate-express-1/node_modules/send/index.js:613:10)
    at onstat (/home/runner/boilerplate-express-1/node_modules/send/index.js:725:10)
    at FSReqCallback.oncomplete (node:fs:199:5)
*
/json request
Error: Can't set headers after they are sent.
    at SendStream.headersAlreadySent (/home/runner/boilerplate-express-1/node_modules/send/index.js:386:13)
    at SendStream.send (/home/runner/boilerplate-express-1/node_modules/send/index.js:613:10)
    at onstat (/home/runner/boilerplate-express-1/node_modules/send/index.js:725:10)
    at FSReqCallback.oncomplete (node:fs:199:5)

That’s how I console.log the functions and how I wrote them:

app.get("/json", (req, res)=> {
  res.json({"message": process.env.MESSAGE_STYLE == "uppercase" ? "HELLO JSON" : "Hello json"});
      console.log("/json request");
    console.log("  message: " + message);
    res.json({ "message": message });
});

app.get("/", (req, res)=> {
  res.sendFile(absolutePath);
      console.log("/json request");
    console.log("  message: " + message);
    res.json({ "message": message });
});

I’m a newbie and tbh I have no idea what does it mean or if I console.log correctly. Still not used to console.log my progress

Something odd is going on with Replit you have an old version of the fcc-express-bground

You should be able to update from the Shell tab with

npm update --save

Or remove it and reinstall it.

npm rm fcc-express-bground
npm i https://github.com/freeCodeCamp/fcc-express-bground-pkg.git

This line won’t work if you don’t define message

This error is telling you not to call res.json twice.

omg thank you!
It was that the problem!

Syntax errors aside (which you have to fix) you need to update the packages.

oh… hehe my bad. Anyway lasjorg saved it. It was running with an old fcc-express-background for some reasons!

yes it worked! Thank you again

I made a PR but I’m not 100% sure if it is a fix or not. I’m hoping it is.

For me, it just won’t install the packages when I click the Run button but for others, it seems to be installing an old version of the testing package.

How did you install the packages? Did you run npm install from the shell or did it automatically install the packages?

1 Like

I did use your command to the shell as you suggested and worked perfectly! npm update --save

I mean originally when starting out how did you install the packages?

Did they get installed automatically when you clicked the Run button or did you have to manually install using npm install.

oh yeah they got installed automatically but I guess they ran an old version for some reasons
I’m just starting using these kind of programs so I’m still getting used to it

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