EatTheBlocks Forum

Get pair price from uniswap v2 and v3

I am trying to use the uniswap v2 on my javascript project. I was able to get the abi of the uniswapV2Pair and the uniswapV2Factory. However i am not understanding how to get the price pair of token from uniswap. Any help will be needed. Plus, from the documentation i am seeing there is really a huge difference btw v2 and v3. Below is my code

const Web3 = require('web3');
const UniswapV2Pair = require('./abis/uniswapV2pair.json');
const UniswapV2Factory = require('./abis/uniswapV2factory.json');

const web3 = new Web3(
     new Web3.providers.WebsocketProvider(process.env.INFURA_URL)
 );

const uniswapFactory = new web3.eth.Contract(
     UniswapV2Factory.abi,
     '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
  )

const loadPairs = async () => {
    uniswapEthDai = new web3.eth.Contract(
        UniswapV2Pair.abi,
        await uniswapFactory.methods.getPair(tokenAddress1, tokenAddress2),
    
       )
  }

I am completely stuck here and dont know how to go further.

Is there a better way of getting the price pair? I will like to know how its implemented on both uniswap v2 and v3