Alright I figured it out. I was not connected on my localhost ganache server, but the main ethereum one. Just needed to create my custom local server in metamask and everything works well now.
The code itself is correct and now I get 5777 as a network id.
In case other newbies like myself would stumble upon same problem, I solved it this way:
Click on the ...