Connect to remote database

Hi - I’m in the process of trying to connect to an external mysql DB. Is using NPM mysql the best way to do this currently? I’ve installed it on the backend but get an error “require” is not defined when I try to use the code from here mysql - npm