How to calculate fee in BitcoinJS raw transaction? I have a transaction with 3 inputs and 2 outputs. 1output is the recipient and the other output is change address. How should I calculate the fee and apply it to output?
The TX fee is the difference between the totals of all the input values and all the output values. If you are looking at a single TX you can see all the output values, but how do you get the input values? They are not included in the TX itself. What you must do is look up the UTXO being spent by each TX input and total their values. (The data structure used to track and process all the input coins is called a "view").

Note that there is no "applying a fee to the output". A TX has no extra fee field or property, and the fee itself does not occupy an entire output.

If you are constructing a TX where the input values equal exactly the output values, you "include" a fee by reducing the value of one of the outputs.