Nomenclature rules are complex. We will only attemp to give names to relatively simple molecules. Look at the following examples of representative molecules bearing ester groups.
Nitriles are formally derived from the dehydration of primary amides.
If the CN is the principal function, its name is included in the main chain with the suffix "nitrile". The numbering starts by it.
Should the CN be a secondary function, it is considered as a "cyano" substituent with its corresponding localizing number.