Building a persistent api/x-press publishing cumulative project

Project Link
Get Help video

Hey everyone so I’m very confused as to why my code is not working the same way that the Get Help video works. I’m going to post my code and the Test Suite info pertaining to what I’m tying to get to come up as test passed just like the help video shows it should do. Any insights would be helpful. I’m sure there’s something I’ve done wrong or I’m missing and I haven’t found it yet. I’m just a little frustrated because I’m still learning how to trouble shoot some of these issues when I’m not as familiar with the code as I might should be. Anyway thanks in advance for helping in any way at all.

My code as it stand right now for the server.js file:

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

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

const app = express();
const PORT = process.env.PORT || 4000;


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


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

module.exports = app;

My api.js file code:

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

apiRouter.use('/artist', artistRouter);

module.exports = apiRouter;

My Artists.js file code:

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;

And the Test Suite return when doing npm test (the Test should show the Get /api/artists at the bottom with a error code of 200 and not 404 for each test, as far as I understand. The rest of the test doesn’t matter to this point of the project.):

$ npm test

> x-press-publishing@1.0.0 test C:\Users\solid\Downloads\capstone-project-1-x-press-publishing\capstone-project-1-x-press-publishing
> mocha

listening on port: 8081

  Artist Table
    √ should exist
    √ should have name, date_of_birth, biography, and is_currently_employed columns with appropriate data types
    √ should have a required name column
    √ should have a required date_of_birth column
    √ should have a required biography column
    √ is_currently_employed should default to 1

  Series Table
    1) should exist
    2) should have id, name, and description columns with appropriate data types
    3) should have a required name column
    4) should have a required description column

  Issue Table
    5) should exist
    6) should have id, name, issue_number, publication_date, artist_id, and series_id columns with appropriate data types
    7) should have a required name column
    8) should have a required name column
    9) should have a required issue_number column
    10) should have a required publication_date column
    11) should have a required artist_id column
    12) should have a required series_id column

  GET /api/artists
GET /api/artists 404 2.233 ms - 150
    13) should return all currently-employed artists
GET /api/artists 404 0.469 ms - 150
    14) should return a status code of 200

If there’s anything you all can help me with on this I would appreciate it. I’m at a loss at this point but I’m still racking my brain to figure out what I might be missing. It could also be something in the files themselves that I have installed or not properly installed or the version or something, but I haven’t found a solution to that being a possibility either.

I’m working on this project right now too. I think this might be it…

The GET path the test is looking for is /api/artists (artists is plural).

In your app.js file in the apiRouter.use() your path argument is '/artist' (singular). So the call never gets passed to your artists.js file since its looking for /artists not /artist.

Hope that helps!

OMG I didn’t even realize this. Thank you, this did it. This was frustrating me so much. haha.

1 Like

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