E-Commerce REST API

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-backend-portfolio-project/modules/fscp-ecommerce-app-rest-api/kanban_projects/ecommerce-app-rest-api

I can’t seem to run the example REST API after following the instructions in the README file. I have setup a database to run locally using PostGres and Postbird GUI and have setup the env variables so that the tables have been successfully generated into the database from the app.
After typing ‘npm run start’ into the command line - the terminal shows the server as listening on PORT 4000. In the browser the localhost address ‘localhost:4000’ returns a cannot GET response. I have tried the other endpoints eg localhost:4000/product to no avail.

Has anyone been able to run the example app?

Thanks :slightly_smiling_face:

I haven’t built it but I took a quick look. I don’t think there is a ‘/product’ path. Did you try a get request to ‘/api/products’ ? The server endpoints all seem to be set up with a router under the api-path.

Hi Mike

Thanks for your response and desire to help.

I have tried ‘/api/products’ and also ‘auth/login’ and still getting the same thing.

Ok. I tried to build it. There appears to be some errors in the setup of it. If you look in the .env-file there is a variable called PGPORT. I think this was set at 3000. But I changed it to 5432 which is a typical port for PG. This got the api connected successfully to the database. I should mention that I created the database manually through psql first and entered credentials in .env.

Then in the same .env-file there is a variable that was called (I think) PORT under Server-configuration. I changed this to SERVER_PORT and set it to 5000 (forgot what it was set to). If you look under /server/config.js you will see that SERVER_PORT is what is referenced from env-variables. This port needs to be the same as the one referenced in /src/setupProxy.js (under target) so set that one to 5000 as well (forgot if it already was 5000). This removed some api-proxy errors that were initially present.

Now if you go to /api/products it will return an empty array (no products in database table) and if you go to http://localhost:3000/ you should see a blue Codecademy Shop Nav-menu but it doesn’t do much more. I did not connect to Google/Facebook OAuth and I don’t see a way to make a local user account from Login Page. So let me know if you get any further!

Hi Mark

Thanks for looking into this.

I can’t actually see the /src/setupProxy.js or target file. Perhaps it’s because I 'm using a mac.
But you definitely have got further than I have.

Sorry, I was referencing the full-stack version of the same project found on this link. The setupProxy.js file is only relevant for the full-stack version.
https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-full-stack-portfolio-project/modules/fscp-ecommerce-app-client/kanban_projects/ecommerce-app-client

But the two versions of the project have much in common. I now built the backend version. It also had PGPORT set to 3000 in .env so I changed this to 5432 (I am assuming this is what most people have for Postgres port). The back-end version is not using the ‘/api’ in the paths. So here the following endpoint returns an empty array:
http://localhost:4000/products
Or you could try this one (will return product not found):
http://localhost:4000/products/1

If this does not help then the next question is if any error messages are present in the terminal…

Thanks Mike

I’ve just entered these endpoints in the browser and happy to say I can also view these. I’ve just used the http://localhost:4000/docs endpoint which displays a Swagger UI and now trying to understand what info this is displaying.

Most appreciate your time and efforts to help me.

1 Like

Great that you got it working. If you enter some data into the tables then those endpoints should return that.

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