module fetch nodejs, node-fetch (ok)

https://www.npmjs.com/package/node-fetch

ok node-fetch

Cai them goi nay no se khong loi su dung cu phap const fetch = require('node-fetch'); thay vì sử dụng cú pháp cũ 
ES Modules (ESM)
import fetch from 'node-fetch';
npm install node-fetch@2
C:\Users\Administrator\OneDrive\Desktop\node\package.json
{
  "dependencies": {
    "node-fetch": "^3.2.3",
    "upper-case": "^2.0.2"
  }
}

C:\Users\Administrator\OneDrive\Desktop\node\myfirst.js

var fetch = require('node-fetch');
let url = "https://jsonplaceholder.typicode.com/posts";
let settings = { method: "Get" };
fetch(url, settings)
.then(res => res.json())
.then((json) => {
    console.log(json);
});

Last updated