Getting host node and node id of field collection

I was killing myself to get host node and node.id of field_collection I am using so I can do some preprocessing before this node is saved. I was trying with field_collection_item_get_host_entity but just couldn't make it work. So I asked google and found out I can do it with regular host function like

$collection = entity_load_single('field_collection_item', $collection_id);
$node = $collection->hostEntity();
echo $node->nid;