npm JS CLI script failing only on windows

Viewed 12

I have a script that works perfectly on macs, but on windows it is failing. I think it has to do with the arguments, but unsure. Here is the script:

const axios = require('axios')
const open = require('open')

const BASE_URL =
  'https://example-api.com'
const args = process.argv.slice(2)
let url = args[0]
  ? `https://${args[0]}-api.com`
  : 'http://localhost:3000'

const api = async () => {
  try {
    const response = await axios.get(BASE_URL)
    const path = response.request.path

    await open(`${url}${path}`)
  } catch (err) {
    console.log(err)
  }
}

api()

The error receiving on windows is:

Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read',
...
0 Answers
Related