Expresso project: Installing dependencies

I’m having trouble installing the dependencies for this project. I’ve tried copying the the package.json file from the solution to the non-solution project folder but this doesn’t seem to help. I still get errors since the project runs very old versions of each of the dependencies. I ran into a similar issue with the X-press publishing project with no success. Does anyone have an idea on how to get around this so I can work on the project?

1 Like

Hi, can you please post a link to the project?

The curriculum catalog is pretty large so it’s difficult to find individual projects without a link :slightly_smiling_face:

2 Likes

Sorry. Here is the link to the Expresso project: https://www.codecademy.com/paths/web-development/tracks/building-a-persistent-api/modules/persistent-api-cumulative-projects/informationals/cumulative-project-expresso

I’ve also had similar issues with the X-press project as well.

1 Like

I looked into it and the project as-is is indeed broken.

Here’s what I did to get the solution code working:

  1. If you already installed an npm packages, you’ll need to completely delete your node_modules folder.
  2. Run this command in order to update your dependencies in your package.json:
    npx npm-check-updates -u
    
  3. After your package.json is updated, you should receive an message in your console telling you what has been updated and asking you to run npm install. Run the npm install command to install the updated dependencies.
  4. Install express, cors and errorhandler (NOTE: you may or may not need cors and errorhandler for your own code, but they were used in the solution code so I had to install them for that.)
  5. Remove the body-parser import since it’s deprecated and now built into express (diff below):
    - const bodyParser = require('body-parser');
      const cors = require('cors');
      const errorhandler = require('errorhandler');
      const express = require('express');
    
  6. Because body-parser’s functionality is now built into express, you need to change bodyParser.json() to express.json() (diff below):
      const app = express();
      const PORT = process.env.PORT || 4000;
    
    - app.use(bodyParser.json());
    + app.use(express.json());
      app.use(cors());
    
  7. Finally, because of a change in mocha a few years ago, I had to alter the test script in package.json to avoid having mocha make my terminal hang indefinitely (diff below):
     "scripts": {
    - "test": "mocha"
    +  "test": "mocha --exit"
     },
    

Anyway, hopefully this helps you get the project sorted out on your end!

Happy coding!

3 Likes

Wow I didn’t even know that body-parser was deprecated. Thank you for answering my question with the level of detail that you did. I’ll try out your solution and hopefully this works. Hopefully sometime soon Codecademy updates this project and the other portions of this course that need attention.

1 Like

Can confirm that dev9923944119’s post works on Node LTS version 18 :slight_smile:

However… I now get complaints about the require and import functions…

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/evelyn/Code/Codecademy/capstone-project-2-expresso-start/node_modules/chai/chai.js from /home/evelyn/Code/Codecademy/capstone-project-2-expresso-start/test/test.js not supported.
Instead change the require of chai.js in /home/evelyn/Code/Codecademy/capstone-project-2-expresso-start/test/test.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/evelyn/Code/Codecademy/capstone-project-2-expresso-start/test/test.js:4:16)