-1

when I try to use fetch() in function in a node environment, it throws me the error.

Command:

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => console.log(json))

Error message:

Error message shreenshot

Why does this kind of error occur and how can I run the fetch() method in my node environment?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 2
    have you read the error message at all? – Jaromanda X Aug 08 '23 at 08:59
  • 2
    The server running at `https://jsonplaceholder.typicode.com/todos/1` should use a free TLS certificate (eg. from Let's Encrypt project) instead of a self-signed certificate – slebetman Aug 08 '23 at 09:22
  • 1
    If the request is really to `jsonplaceholder.typicode.com` then something seems to be wrong on your system. Because `jsonplaceholder.typicode.com` has a valid certificate. There can be various problems here. Like: **1.** The system might not resolve the ` `jsonplaceholder.typicode.com` domain to the correct IP, **2.** there is something wrong with the CA Store on your system (or it is outdated and does not trust the Let's Encrypt Root). **3.** maybe the date on your system is wrong (but that should lead to a different error) – t.niese Aug 08 '23 at 09:29
  • Possible duplicate of this :- https://stackoverflow.com/questions/45088006/nodejs-error-self-signed-certificate-in-certificate-chain – LakShan Aug 08 '23 at 11:42

0 Answers0