'in JavaScript what is the equivalent of python open(filepath, 'rb')

I can open the file in binary mode with Python and store it in a variable. I have been researching this for two days, and I can't seem to find a straightforward answer. I need this because I have been working on a project that we have completed in Python, but we need to convert it into JavaScript. The issue that I'm having is that I need to send a file through an API call. Still, every time I do, I get this error ' HTTP 415 Unsupported Media TypeThe provided media type is not supported for the requested URI. What I have is a JSON file that I need to pass to a post-call in binary

files = {'file': open(JSON_File, 'rb')}
response = requests.post(
    URL, 
    auth=(USERNAME, PASSWORD),
    files=files
    #files=files, verify = False
)

response.text

how can I do this in nodeJS? I completed the above already in Python.

Here is what the the files variable prints from the python code.

files = {'file': open(JSON_File_path, 'rb')}

print(files) => {'file': <_io.BufferedReader name='my_json_file.json'>}

Here is and example of what my json file contains:

    [
  {
    "resourceType": "Domain",
    "identifier": {
      "name": "ZZ_CRM",
      "community": {
        "name": "Intermediate APIs"
      }
    },
    "type": {
      "name": "Data Asset Domain"
    }
  },
  {
    "resourceType": "Domain",
    "identifier": {
      "name": "ZZ_Source to Target Mappings",
      "community": {
        "name": "Intermediate APIs"
      }
    },
    "type": {
      "name": "Mapping Domain"
    }
  },
  {
    "resourceType": "Asset",
    "identifier": {
      "name": "Client Name",
      "domain": {
        "name": "ZZ_CRM",
        "community": {
          "name": "Intermediate APIs"
        }
      }
    },
    "type": {
      "name": "Data Element"
    }
  },
  {
    "resourceType": "Asset",
    "identifier": {
      "name": "Client ID",
      "domain": {
        "name": "ZZ_CRM",
        "community": {
          "name": "Intermediate APIs"
        }
      }
    },
    "type": {
      "name": "Data Element"
    }
  },
  {
    "resourceType": "Asset",
    "identifier": {
      "name": "SQL Server Mapping",
      "domain": {
        "name": "ZZ_Source to Target Mappings",
        "community": {
          "name": "Intermediate APIs"
        }
      }
    },
    "type": {
      "name": "Mapping Specification"
    }
  },
  {
    "resourceType": "Complex Relation",
    "identifier": {
      "relations": {
        "00000000-0000-0000-0000-000000007088:TARGET": [
          {
            "name": "SQL Server Mapping1Name",
            "domain": {
              "name": "ZZ_Source to Target Mappings1Name",
              "community": {
                "name": "Intermediate APIs1Name"
              }
            }
          }
        ],
        "00000000-0000-0000-0000-000000007089:TARGET": [
          {
            "name": "Client ID",
            "domain": {
              "name": "ZZ_CRM",
              "community": {
                "name": "Intermediate APIs"
              }
            }
          }
        ],
        "00000000-0000-0000-0000-000000007090:TARGET": [
          {
            "name": "SQL Server Mapping",
            "domain": {
              "name": "ZZ_Source to Target Mappings",
              "community": {
                "name": "Intermediate APIs"
              }
            }
          }
        ]
      }
    },
    "complexRelationType": {
      "name": "Field Mapping"
    },
    "attributes": {
      "Transformation Logic": [
        {
          "value": "`clientsWithType` AS select `client`.`client_id` AS `id`, concat( concat( `client`.`name`, ' ' ), `client`.`surname` ) AS `fullname`, `client_type`.`value` AS `client_type`, `client`.`email_address` AS `email_address` from ( `client` join `client_type` on (( `client`.`client_type` = `client_type`.`code` )));"
        }
      ]
    }
  }
]


Solution 1:[1]

You could use fs module that's included in nodejs

fs.readFileSync(file_path);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1