'How to run an hardhat script on NodeJs so that you can fork multiple evm chains on different ports?

I want to be able to fork more chains (ethereum, bsc, etc.) than just one on my system.
Hardhat doc shows, how to fork 1 chain npx hardhat node --fork https://... and it works fine.
But I would like to fork them programmatically on a Nodejs script.

When I try to fork a chain on NodeJs like below, it does not work. What can I do?

Thanks!


`hre.config.networks.networks = {
     hardhat: {
        forking: {
          url: http://localhost:8545
        },
    }
}     

await hre.network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: http://localhost:8545,
          chainId: chainObj.chain_id,
          blockNumber: blockNumber, 
        },
      },
    ],
});

`



Sources

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

Source: Stack Overflow

Solution Source