A
A
ArtemEfremov2020-06-01 12:06:41
JavaScript
ArtemEfremov, 2020-06-01 12:06:41

Failed to fetch - Node.js?

Hello. When I go, for example, through a browser to the address example.com:6470, I get "Hello World", listening to the port is started via express.

But when I try to make a request with a third-party script, either via fetch() or via request() to the same address, it sends a "Failed to fetch" error, what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2020-06-01
@ArtemEfremov

Connect the cors npm install corspackage to express and use app.use(cors()) before the routes. And he runs into another problem. req.body for some reason is only there if you submit the form from the current domain, he just started to study this stack for this xs why. To read data, you need the body-parser package. How to connect infa is in the docks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question