Anda perlu menambahkan nilai socket path
ke db_config
objek:
db_config.socketPath = '/var/run/mysqld/mysqld.sock'
Misalnya di MAMP, buka http://localhost:8888/MAMP , dan Anda menemukan:
/Applications/MAMP/tmp/mysql/mysql.sock
Pada akhirnya Anda memiliki:
var connection = mysql.createConnection({
host : db_config.host,
user : db_config.user,
password : db_config.pass,
database : db_config.db,
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
});