P5.js application with backend

You should be able to just leave the connect() argument empty and it’ll by default try to connect to the same location it was served from. https://socket.io/docs/client-api/#io-url-options

the connect/io argument is a 'url' *(String)* (defaults to 'window.location' )

let socket = io.connect(); should get you connected to window.location which should work flawlessly if you’re serving out your express and socket setup on the same port and url/ip

see here for an example:
server: https://github.com/bmoren/realtimewebapp/blob/master/app.js
client: https://github.com/bmoren/realtimewebapp/blob/master/public/frontend.js