Information Security Projects - Stock Price Checker

Tell us what’s happening:
Im working on the stock price checker project and having trouble importing the json data from the provided url. At first i was getting an error when i tried to require node-fetch. Now that I changed require to import, I’m getting the following error:

"typeError: fetch is not a function. " when Im fetching the url inside my async function.

Im not sure what I’m doing wrong here. please help

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Information Security Projects - Stock Price Checker

Link to the challenge:

You don’t really need node-fetch, Node.js has its own fetch. It is still considered experimental but it should work just fine.

fetch (experimental)

You can use the CommonJS version of node-fetch by installing v2 npm install node-fetch@2.

You should really add the --watch flag to your start script or use nodemon so you can see the errors on Replit and it doesn’t just restart on you when it crashes.

Thanks!, that worked. my code compiles now. My new problem is when i submit my link to fcc, the fcc tests time out. not the functional tests that we have to write as part of the challenge. I haven’t written those yet. could it by my async functions causing this?

You have syntax errors.

TypeError: Cannot destructure property ‘symbol’ of ‘(intermediate value)’ as it is undefined.

Line 23: return symbol, latestPrice;

That is not how return works (you can only return one thing). Also, you are destructuring the value at the call site so you must be expecting an object.

Line 68: const { symbol, latestPrice } = await fetchData(stock);

const oneStockData = await saveData(symbol, like, req.ip);
console.log("One Stock Data", oneStockData);

  stockData: {
    stock: symbol,
    price: latestPrice,

The identifiers do not match. oneStockData vs OneStockData

Didn’t look further. There might be more.

hmm. I have installed nodemon too now but somehow it still doesn’t show me any syntax errors. Its annoying

Does it show you it is using nodemon in the console when you start the server? It should pause on errors/crashes and wait for a code change.

You can try --watch instead as well.

it does show nodemon starting everytime i make a change an it autosaves. i’ll try --watch too

But is it not crashing for you when you submit it for the tests?

nope, it just says “requested” when i submit the link and then on the fcc page i get the timeout errors and thats how i know something’s wrong. nothing from replit console

Odd. This is what I see.

Personally, I would work on this locally and then transfer the code to Replit for the final submission. If you push it to a repo you can create the Replit using that repo (to avoid having to copy/paste).

Edit: I guess if you need help with the code a Replit isn’t a bad idea. Otherwise, you have to remember to push your code if you use a repo instead.

yea, I started doing these projects locally initially and it was much better to work but when i run into problems its easier to ask using replit. I tried managing both but i guess Im too lazy to copy paste every time i change something

I haven’t actually tried it (or I just don’t remember doing it). But if you create the Replit from a repo you should be able to pull from it.

So you work locally, push to a repo, create the Replit from the repo, and then each time you push to the repo you pull the changes to the Replit. At least I think that is how it works. It is a bit more work I guess but it might be worth it for the local dev expirence.

you’re right. that’s how it intended to work but when i tried to connect replit and github I had some errors. I tried for two days and then gave up.