Information Security Projects-Stock Price Checker

For the security project Stock Price Checker, do I set up the mongoDB connection? Or is that already set up on the back end and connected to express and I need only add my database connect string to the .env file ( assigned to the variable DB ) ?

Thanks

I would say to just set this DB variabe accordingly, It might help to do the mongoDB tutorial online if you need more info.

You have to set it all up. The starting dependencies also do not have mongodb or mongoose.

I think that text is just a leftover from before this PR.

https://github.com/freeCodeCamp/boilerplate-project-stockchecker/pull/13/files#diff-f7fe12d2c7d19f5ad25e06e720cc425b2f45efdc24403ef513484365bf3b886d

It should probably just be removed so that it only mentions the test env value.

Edit: I made a PR that removed the leftover text.

:pray:t6: Thank you very much!

Sorry! One more question:

I’ve been reviewing previous modules ( ex. Express/Node/Api ), but for this Stock Checker I can’t figure out where I would put the base url : https://stock-price-checker-proxy.freecodecamp.rocks/.

In the server.js file an express instance is already instatiated, and I succefully connected to mongodb , and I see starter code in the api.js file for api calls to specific routes, but where do I utilize the base url ? I need hints on this concept…

Typically, setting up the MongoDB connection involves configuring it on the backend for projects like the Stock Price Checker. You’d usually need to ensure MongoDB is installed and running, then connect it to Express using Mongoose or a similar library. Adding your database connection string to the .env file (assigned to DB) is part of configuring this connection securely. Double check the documentation or contact the project maintainers for clarity if unsure.

Thanks, I’ve already established connection with Monggodb atlas using mongoose. I’m not clear on the api call to https://stock-price-checker-proxy.freecodecamp.rocks/. I am unsure of how to plan the design of the connection, particularly, where to use this base url. I understand where to access specific paths ( ex. “/stock-price”) but I am unsure where I connect to the base url as a whole.

The backend should fetch from that API.

So I need to use the request module ? Most of the examples from previous modules use the local host and made up data to insert into mongoDB. When calling a real website it seems like I might have to use the ‘request’ module? and ‘fetch’ ? To call just a specific path is not enough because the base is not my local host? Is that correct?

You can fetch on the backend just as you do on a client.

Current Node versions include fetch, but you can also use libraries if you prefer (Request is deprecated, so I wouldn’t use that Alternative libraries to request).

Not really sure what you mean here?

https://stock-price-checker-proxy.freecodecamp.rocks/ is an API proxy. The “landing page” is just a usage example page, if you hit the actual API endpoint you will get back JSON.

https://stock-price-checker-proxy.freecodecamp.rocks/v1/stock/msft/quote

Let me share my code, might be easiest. I am still not able to access the stock data. I was hoping for data to be returned in the form of json…
https://freecodecam-boilerplate-pwuqtwhppik.ws-us114.gitpod.io/

We can’t see your code. You have to share a workspace. Or post a repo or use something like Replit/Glitch.


The API does return JSON.

Example:

app.get("/:symbol?", async (req, res) => {
  const symbol = req.params.symbol ?? "goog";
  const data = await fetch(
    `https://stock-price-checker-proxy.freecodecamp.rocks/v1/stock/${symbol}/quote`,
  );
  const json = await data.json();
  res.json(json);
});

My apologies. Are you able to access my code through this snapshot?
https://gitpod.io/#snapshot/7a38d747-d1bf-49af-962e-90fd69995e0b

I tried running your code as well and I don’t get an error but I also don’t get a json returned in the console.

Yes, I can see your code.

Why are you expecting it in the console? You are sending it, and you are serving the static file on the / route.

If you go to the param path you should see the JSON.

Example:

https://3000-ivory-slug-c2dpn3omixo.ws-eu114.gitpod.io/goog

Oh I see… Thanks for that.

And I noticed you used the url:

https://stock-price-checker-proxy.freecodecamp.rocks/v1/stock/

not

https://stock-price-checker-proxy.freecodecamp.rocks/api/stock-prices/

Should the query path be v1/stock or api/stock-prices?

It should be v1, that is the API version and is the endpoint given in the API docs.


As an aside, API versions are used so that if an API introduces breaking changes, it can do a version bump. That way, the old API can live side by side with the new version (until the old is potentially deprecated). It is just a good practice to version an API.

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