Skip to content

Configuring MySQL for Local Dev vs Azure Deployment

Jared edited this page May 18, 2018 · 1 revision

The following change needs to be made to the mainRoutes.js file depending on your required configuration:

Local config:

let connection = mysql.createConnection({
	host: 'localhost',
	user: 'root',
	password: 'password',
});

Azure config:

let connnect_config = function () {
	// Process the environment variable defining the MySQL connection parameters
	let str = process.env.MYSQLCONNSTR_localdb
	let reg = str.split(';');
	let database = reg[0].split('=')[1]
	let source = reg[1].split('=')[1]
	let [host, port] = source.split(':')
	let user = reg[2].split('=')[1]
	let password = reg[3].split('=')[1]

	// Create the connection and return
	let auth = {
		host: host,
		user: user,
		password: password,
		database: database,
		port: parseInt(port)
	}
	return mysql.createConnection(auth)
}

let connection = connnect_config();