So we get that "In the beginning was the Word, and the Word was with God, and the Word was God."
How did God come to be "In the beginning"?
Genesis 1:1 God is the uncreated Creator. He is self-existent with no beginning and no end, an eternal, personal, triune spirit.
We cannot fathom how God has always existed, but we know something has always existed. Is it personal or impersonal? God or matter? Something does not come from nothing, but God is the uncreated Creator, the first cause of the universe. This blows our minds and leads to worship, even if we do not understand it.
"He is there and He is not silent" Francis Schaeffer
The verse you refer to is Jn. 1:1 It is talking about Jesus who is God Almighty in the flesh. The Greek grammar shows that when there was a beginning of the material universe and our unique measure of time (Gen. 1:1), the Word/Jesus was already preexisting (imperfect, continuous tense). This eternal Word was with the Father (face to face) as the triune God. He is also of the nature/essence/substance of God. He is uncreated Creator co-equal, co-existent, co-eternal as Father, Son, and Holy Spirit (one God with 3 personal distinctions).
This invisible God added humanity and became the God-Man, the Lord Jesus Christ, one person with two natures (God with a face). The flesh of Jesus is not eternal, but He Himself as the Word is. He is now risen from the dead returning to His former glory at the right hand of the Father. He will return as the King of kings and Lord of lords.
Do you know and love Him? If not, would you like to? Jn. 3:16; Rom. 1:16