You don't necessarily, you have to learn not to give in to them until they go away. I know, easier said than done.
There's a lot of healthy things you can eat instead. If you're craving chocolate, eat dark chocolate, something salty, eat almonds or another healthy lightly salted snack. Look a few things up that you can substitute for junk food. If you just want to bored eat, do something that will keep you busy to keep your mind off it, or you can drink green tea or brush your teeth and you wont want to eat anymore. Just be careful not to do it too much, brushing too much is bad for your teeth