0

I've successfully changed my MySQL port from 3306 to 3400 and it works great on the workbench. However, I want to change the default port when I run npm script as well as it still runs on 3306, how will I change its default port.

The idea is I want to have an isolated port when I work on both Laragon (which should run on 3306) and MySQL port: 3400 (when I run npm on my VS Code and have my database queried).

I can't exactly find a question about this since I also don't know what exactly will I search in this scenario. Thank you very much for the help.

Shironekomaru
  • 361
  • 1
  • 6
  • 15
  • Seems like this has been answered here: [How to tell node.js that mysql is not running on default port?](https://stackoverflow.com/questions/9041728/how-to-tell-node-js-that-mysql-is-not-running-on-default-port) – Daniel W. Sep 02 '21 at 10:10
  • @DanielW. thank you very much. Using this solution worked. This way I have a separate port running for my VS Code and also a different port for running Laragon. – Shironekomaru Sep 02 '21 at 10:32

1 Answers1

1

When you creating the MySQL connection you can provide your port also

var client = mysql.createClient({
  userName: 'uname',
  password: 'pass123',
  port: 3400
});

Also, it's better to create a .env file and define your userName, password, port, API keys,etc on there and use the env variable to access those details.

so with env,

var client = mysql.createClient({
  userName: process.env.DB_USER,
  password: process.env.DB_PASS,
  port: process.env.PORT
});
S.Sachith
  • 536
  • 1
  • 9
  • 21