"For by grace are ye saved through faith; and that not of yourselves: it is the gift of God, NOT OF WORKS, lest any man should boast." - Ephesians 2:8-9
"FAITH by ITSELF, if it does not have WORKS, is DEAD" - James 2:17
This is one of the supposed contradictions skeptics bring up. "Paul said we're not saved by works yet James does". But James said nothing of the sort. James said those who are truly born again will produce the fruits of the spirit (Galatians 5:22-23) but if you're not truly saved, you won't produce the fruits of the spirit. We're saved not by works, we're saved by grace through faith. But After we get saved, we naturally produce good works. That’s not to say we become perfect, but our Christianness shows. Jesus Himself taught this very same thing. For example, he put emphasis on good works in order to show the world that we are His disciples and so that they might praise Him in Heaven. People will know we are Christians by our behavior as well as our words. Jesus said "So now I am giving you a new commandment: Love each other. Just as I have loved you, you should love each other. Your love for one another will prove to the world that you are my disciples." - John 13:34-35 and before that, He said in the sermon on the mount, “You are the light of the world. A city on a hill cannot be hidden. Neither do people light a lamp and put it under a bowl. Instead they put it on its stand, and it gives light to everyone in the house. In the same way, let your light shine before others, that they may see your good deeds and glorify your Father in heaven." - Matthew 5:14-16
So, in summary, James is not saying that we are saved by works. He's saying that salvation produces works, and if you produce none of the fruits of the spirit, how will other people know that you are saved? Your faith will be completely invisible before men. While God can see our faith since He knows what's in our hearts (1 Samuel 16:7, Deuteronomy 31:21, Psalm 44:21, Psalm 139:2, Proverbs 15:11), men can only judge us by our actions (Matthew 7:16-19). Before I wrap this up, I'd like to point out to those of you who may be wondering that Jesus condemned doing good actions in public in order to bring glory to ourselves (see Matthew 6:1-18), but He commanded that we do good works in public in order to bring glory to The Lord (see Matthew 5:14-16). Whenever we are going to do a good work, we must think carefully on whether it's going to bring glory to The Lord or bring glory to ourselves. If it only brings glory to ourselves, we should heed Jesus' command to do our good works privately, to not "let the left hand know what the right is doing". If it will bring glory to God, we should do indeed do it publicly. And if people give us praise, we should redirect them to the One who truly deserves the praise. If they insist on glorifying us, we should continuously redirect them to The Lord. All glory goes to God.
In the same way that a tree produces fruit and not the other way around, salvation produces works and not the other way around. If a tree that's supposed to produce fruit doesn't produce fruit, what do we conclude? We conclude that the tree is dead!