Note of Node.js

1, Error: Cannot find module ‘mysql’.

Option #1: The development environment is Netbeans on Macbook. On the terminal, enter the folder of the project and run the command: npm install mysql. Then it shows another error as 2#.

Option #2: Install in the default ‘usr/local/bin/node_modules’ path and then use ‘ln -s’ to build a symbolic link.

2, Error: connect ECONNREFUSED 127.0.0.1:3306

On the terminal, use the command ‘find / -type s’, find :

/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

Add it to the configuration:

var con = mysql.createConnection({
host: “localhost”,
user: “***”,
database : ‘***’,
password: ‘***’,
socketPath: ‘/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock’
});

Then, it is connected successfully to the MySQL database.

Leave a Reply

Your email address will not be published. Required fields are marked *