X-press publishing Step 23 - Issue with npm test

Hi everyone,

https://www.codecademy.com/paths/web-development/tracks/building-a-persistent-api/modules/persistent-api-cumulative-projects/projects/x-press-publishing

I’m working on the Xpress capstone project and I’m running into an issue with the npm test module. It is not logging my first get router as passed. Has anyone else run into this problem and fixed the issue?

Here’s the following code I have written. Please let me know if you need more info.

Server.js

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

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

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

app.use(bodyParser.json()); //req.body
app.use(cors);
app.use(morgan('dev'));

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

app.use(errorhandler);

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

module.exports = app;

api.js

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

apiRouter.use('/artists', artistsRouter)

module.exports = apiRouter;

artists.js

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) {
	  next(err);
	} else {
	  res.status(200).json({artists: artists});
	}
  });
});


module.exports = artistsRouter;

npm test screenshots


BASH Test results 2

After troubleshooting more, I think this issue has to do with the Error: Timeout of 2000ms exceeded. I’ve extended this timeout in the package.json to 5000ms but I am still getting the same results. Anyone know what the source of this error is?

After more troubleshooting, I found that

Should have been written as app.use(cors());

This has fixed my tests.

1 Like

Well done on finding and solving it yourself.