const fetch = require("node-fetch") ;(async () => { if (process.argv.length < 3) { console.error("Needs at least two arguments.") process.exit(1) } // node index.js url data const url = process.argv[2] const data = process.argv[3] let dataAsJson try { dataAsJson = JSON.parse(data) } catch (e) { console.error("Second argument (data) is not valid JSON.") process.exit(1) } // Do fetch f = await fetch(url, dataAsJson) if (!f.ok) { console.error(JSON.stringify(f)) return } // Await parse asJson = await f.json() console.log(JSON.stringify(asJson)) })()