0

I am using Node Js as backend and basic html css js for frontend. I am sending request through node js that

app.get("/send", async (req, res) => {
  let products = await Product.find();
  products = await products;
  res.send(products);
});

and getting fetch on an html page:

const getData = async () => {
    const response = await fetch("localhost:3000/send", {
      method: "GET",
    });
    const data = await response.json();
    console.log(data);
  };
  getData();

But i am not getting the data, I have tested the api on Postman it works fine there. But throwing error on browser:

Error is :

Fetch API cannot load localhost:3000/send. URL scheme "localhost" is not supported.

Please help me out. Bundles of thanks!

1
  • 4
    Add http:// or https:// Commented Jun 8, 2022 at 5:12

1 Answer 1

3

You should specify localhost as being http://localhost or https://localhost - otherwise fetch can't be sure which protocol you are mentioning:

const response = await fetch("http://localhost:3000/send", { ... });
Sign up to request clarification or add additional context in comments.

1 Comment

The http would be redirected to https. Why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.