X-Press Publishing Step 23

Hello! I’m working on Step 23 from the X-Press Publishing project. I can’t pass the GET /api/artists test. I tried to find where I made a mistake but I didn’t see it :frowning_face:

Can anyone give me a piece of advice on where I may make a mistake?

Down below you will find my code:


const bodyParser = require('body-parser');
const cors = require('cors');
const errorhandler = require('errorhandler');
const morgan = require('morgan');
const express = require('express');

const apiRouter = require('./api/api');

const app = express();

const PORT = process.env.PORT || 4000;


app.use('./api', apiRouter);


app.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);

module.exports = app;


const express = require('express');
const apiRouter = express.Router();
const artistsRouter = require('./artists.js');

apiRouter.use('/artists', artistsRouter);

module.exports = apiRouter;


const express = require('express');
const artistsRouter = express.Router();

const sqlite3 = require('sqlite3');
const db = new sqlite3.Database(process.env.TEST_DATABASE || './database.sqlite');

artistsRouter.get('/', (req, res, next) => {
    db.all('SELECT * FROM Artist WHERE Artist.is_currently_employed = 1',
      (err, artists) => {
        if (err) {
        } else {
          res.status(200).json({artists: artists});

  module.exports = artistsRouter;

The test results:

 GET /api/artists
GET /api/artists 404 2.364 ms - 150
    13) should return all currently-employed artists
GET /api/artists 404 0.250 ms - 150
    14) should return a status code of 200
13) GET /api/artists
       should return all currently-employed artists:
     TypeError: Cannot read property 'length' of undefined
      at D:\RUX\Codecademy\capstone-project-1-x-press-publishing\capstone-project-1-x-press-publishing\test\test.js:272:26
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  14) GET /api/artists
       should return a status code of 200:
     Error: expected 200 "OK", got 404 "Not Found"
      at Test._assertStatus (node_modules\supertest\lib\test.js:268:12)
      at Test._assertFunction (node_modules\supertest\lib\test.js:283:11)
      at Test.assert (node_modules\supertest\lib\test.js:173:18)
      at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
      at emitCloseNT (net.js:1655:8)
      at processTicksAndRejections (internal/process/task_queues.js:83:21)

Thank you!

Hi @dev7690636230! Thanks for posting, can you link us to the project?

Also, you mentioned this:

Would you be able to walk us through your thought process? What exactly have you tried?

Hi! This is the link to the project: https://www.codecademy.com/paths/web-development/tracks/building-a-persistent-api/modules/persistent-api-cumulative-projects/projects/x-press-publishing

First, after I ran the test and I saw that it didn’t pass, a read the error and I get that it mid be a typing error. I check my code and fix the error mistakes that I find. I remade the test. It didn’t pass. I watch the hint on step 23 and it seemed I did the exact thing in my code, as in the hint. After that, I watch the Get Help Video and it seems I made the exact things the programmer in the video did. I compared the code in the video and mine. I still did not see where is my mistake. I entered the forum and read all the conversations on the project X-Press Publishing regarding problems on step 23. The solutions that I find reading these conversations were usually about a typing error. My code did not seem to have the same typing error that others had. I read my code many times and I did not manage to see where I made a typing error. If I made another type of mistake I did not see it :frowning_face:

I want to add that I saw in the test results this TypeError: Cannot read property ‘length’ of undefined, and the path leads to the file test.js line 272. But I have not worked on this file at all. I don’t understand where I did wrong. Thank you for your time.

Hi @dev7690636230,

I’m having the exact same problem as you.
Let me know if you figure out any solutions. :grinning:


If your code matches @dev7690636230’s code, then it is because of this line:

app.use('./api', apiRouter);

changing it to this works:

app.use('/api', apiRouter);
1 Like


I’d actually put a period in api.js at apiRouter.use('/artists', artistsRouter); but it’s the same problem still.

Thanks for pointing this out @selectall!

1 Like

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