Back End Development and APIs Replit Issue

While working on the Back End Development and API certification I have been running into this issue where I’m unable to run the app in Replit. Currently, it’s throwing this error message in the console:

I have been able to work around the issue by refreshing the page and then trying to run the app again. The same issue occurs however, I’m able to pass the challenge.

Any thoughts as to how I can resolve this issue or is this more on FCC’s end?

Please post your Replit

Did you remember to click the “Done” button when importing the boilerplate?

It shouldn’t be looking for an index.js file as the run command is npm run start and the script is start: node server.js

Here is the link to my Replit related to this issue:
https://replit.com/@DonovanFerrel/boilerplate-express

I don’t believe there was a “Done” button only an “Import” one, I tried to go back a step to when I initially imported the boilerplate and that’s what I currently see. I even tried to create a new Replit using this boilerplate and the same error occurred.

If you use Replit, follow these steps to set up the project:

  • Start by importing the project on Replit.
  • Next, you will see a .replit window.
  • Select Use run command and click the Done button.

Done-button


Edit: Your run command in the .replit file doesn’t look correct run = ["node", "index.js"] it should be run = "npm run start"

In the top right of the file explorer use the three dots and make sure it is set to show hidden files. Then edit the .replit file to use the run command I posted above.

This is how the content of the .replit file looks on a fresh import.

modules = ["nodejs-18:v3-20230608-f4cd419"]
hidden = [".config", "package-lock.json"]
run = "npm run start"

[nix]
channel = "stable-23_05"

[deployment]
run = ["sh", "-c", "npm run start"]
deploymentTarget = "cloudrun"
ignorePorts = false

Thanks for your quick responses!

I tried that by creating a new instance with the boilerplate, doing that seemed to have resolved the issue partially. That config file appears to match your screenshot however, I am getting the following error on the host view.

image

It isn’t an error. Your server is just not serving anything yet.

Understood, however, I can see there is an index.html page in the views folder. Shouldn’t it be displaying that page to complete the last challenge of the “Basic Node and Express” section?

The only Replit I see is the one you linked to earlier and it does not have any code that uses the view folder. It is added in this challenge.

I have gone back through each section as I realized there was code that is needed to continue further on. I’m on the last section now and running into the values received from the POST being “undefined.” I’m assuming there is something I’m missing or just not quite understanding fully. Here is my code:

let bodyParser = require("body-parser");
let express = require('express');
let app = express();

// 1.
// console.log("Hello World");

// 2.
/*
app.get("/", (req, res) => {
  res.send("Hello Express");
});
*/

// Middleware
app.use(bodyParser.urlencoded({ extended: false }));

// 4. Adds page styling
app.use("/public", express.static(__dirname + "/public"));

// 7. Implements root level request logger middleware
app.use((req, res, next) => {
  console.log(req.method + " " + req.path + " - " + req.ip);
  next();
});

// 3. Fetchs index page
app.get("/", (res, req) => {
  req.sendFile(__dirname + "/views/index.html");
});

// 5. Fetchs json data
app.get("/json", (req, res) => {
  res.json({ "message": "Hello json" });
});

// 6. Implements .env file
app.get("/json", (req, res) => {
  if (process.env.MESSAGE_STYLE === "uppercase") {
    res.json({ "message": "Hello json".toUpperCase() });
  } else {
    res.json({ "message": "Hello json" });
  }
});

// 8. Implements time server
app.get("/now", (req, res, next) => {
  req.time = new Date().toString();
  next();
}, (req, res) => {
  res.json({ "time": req.time });
});

// 9. Implements echo server
app.get("/:word/echo", (req, res) => {
  res.json({ "echo": req.params.word });
});

// 10. Implements name server
app.get("/name", (req, res) => {
  res.json({ "name": req.query.first + " " + req.query.last });
});

// 12. Implements post request
app.post("/name", (req, res) => {
  res.json({ "name": req.body.first + " " + req.body.last });
});

module.exports = app;

I am now able to pass the challenge the code pasted above. For some reason the undefined value was shown through the host on Replit but not when I opened it from its own tab.