Musíte přidat hodnotu socket path
do objektu config:
socketPath: '/var/run/mysqld/mysqld.sock'
V MAMP přejdete na http://localhost:8888/MAMP a najdete:
/Applications/MAMP/tmp/mysql/mysql.sock
Na konci máte:
var connection = mysql.createConnection({
host : config.host,
user : config.user,
password : config.pass,
database : config.db,
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
});