While verifying previous blocks, how does the node know the difficulty at nth block?
Contrary to popular belief, the difficulty is not actually based on the number of leading zeros, that's just an oversimplification to help people understand what difficulty is. Rather the difficulty is based on the value of the block hash when interpreted as an integer. The difficulty of a block must be less than or equal to a target value. The target value is adjusted every 2016 blocks and is encoded in a compact form in every single block (it is part of the block header).

When a node is syncing, they start with the target value encoded in the genesis block. Every 2016 blocks, a very simple algorithm is run to calculate the target value for the next 2016 blocks. This algorithm is deterministic, so given the same set of blocks, all nodes will result in the same target value calculation. In this way, a node which has validated from the genesis block can know exactly what the target value for the nth block in the blockchain must be.