Node-fetch problems with POST requests

You need to await for json. var sentiments = await fetch(SEN_URL, {method: “POST”, body: {“data”: [{“text”: “I love you”}, {“text”: “I hate you”}]}}) //Here await sentiments.json() Also you can make request with JSON.stringify() for body. And it will be easier to manage your js object. Like this: var data = {data: [{text: “I love you”}, … Read more

How to ignore SSL certificate validation in node requests?

Axios doesn’t address that situation so far – you can try: process.env.NODE_TLS_REJECT_UNAUTHORIZED = ‘0’; BUT THAT’S A VERY BAD IDEA since it disables SSL across the whole node server. Or, you can configure axios to use a custom agent and set rejectUnauthorized to false for that agent as mentioned here. Example: const https = require(‘https’); … Read more

node-fetch 3.0.0 and jest gives SyntaxError: Cannot use import statement outside a module

Fetch 3.0 is designed for using esmodules instead of commonjs. Therefore you have to make sure you import it into a module. For example: to import it to app.js : Add “type”:”module” in your package.json and then import it. For importing it to other files or app.js even, you can also change the extension from … Read more

Node-fetch: Disable SSL verification

The other way to do is to set your own agent to the fetch call. const fetch = require(‘node-fetch’); const https = require(‘https’); const httpsAgent = new https.Agent({ rejectUnauthorized: false, }); const response = await fetch(url, { method: ‘POST’, headers: headers, body: body, agent: httpsAgent, });

Error: require() of ES modules is not supported when importing node-fetch

From the Upgrade Guide node-fetch was converted to be a ESM only package in version 3.0.0-beta.10. node-fetch is an ESM-only module – you are not able to import it with require. Alternatively, you can use the async import() function from CommonJS to load node-fetch asynchronously: // mod.cjs const fetch = (…args) => import(‘node-fetch’).then(({default: fetch}) => … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)