Cannot Get /

Im doing the beatbox challenge:
https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-javascript-arrays-loops-and-iterators/modules/project-beat-mix/informationals/bapi-p2-beat-mix

When i run npm start server it starts all right on port 4001. When i go to 127.0.0.1:4001 all i get is “Cannot Get /”. Im not sure if this is part of the challenge? but i cant test the code ive written till i fix this.

iv tried with chromium:
Version 76.0.3809.100 (Official Build) Built on Ubuntu , running on LinuxMint 18.3 (64-bit)

and firefox: 68.0.2

any help appreciated!!

What happens when you open http://127.0.0.1:4001/presets? You should get some output.


In the server.js file you can find these routes:

app.get('/presets', (req, res, next) => {
  res.send(presets);
});

// Handle presets requests
app.use('/presets/:id', (req, res, next) => {
  let index = Number(req.params.id);
  let presetArray = req.body;
  let isValidPreset = presetArray.length === 4
  && presetArray.every((singleRow) => {
    return singleRow.length === 16
    && singleRow.every((singleGridElement) => {
      return singleGridElement === true || singleGridElement === false;
    });
  });
  if (app.method === 'PUT' && !isValidPreset) {
    res.status(400).send('Bad Request, send a preset array!');
  } else {
    let method = req.method;
    let [status, preset] = presetHandler(method, index, presetArray);
    res.status(status).send(preset);
  }
});

As you can see, there are no routes definition for app.get('/', ..., that is why server responded with Cannot Get / error.

3 Likes

Yeah ‘http://127.0.0.1:4001/presets’ gave me an array of arrays containing false… So i need to set “apt.get(’/’,” to point to index.html??