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?
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
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.
I looked into it and the project as-is is indeed broken.
Here’s what I did to get the solution code working:
- If you already installed an npm packages, you’ll need to completely delete your
node_modules
folder. - Run this command in order to update your dependencies in your
package.json
:npx npm-check-updates -u
- After your
package.json
is updated, you should receive an message in your console telling you what has been updated and asking you to runnpm install
. Run thenpm install
command to install the updated dependencies. - Install express, cors and errorhandler (NOTE: you may or may not need
cors
anderrorhandler
for your own code, but they were used in the solution code so I had to install them for that.) - 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');
- Because body-parser’s functionality is now built into express, you need to change
bodyParser.json()
toexpress.json()
(diff below):const app = express(); const PORT = process.env.PORT || 4000; - app.use(bodyParser.json()); + app.use(express.json()); app.use(cors());
- 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!
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.
Can confirm that dev9923944119’s post works on Node LTS version 18
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)