[Node.js] mysql2パッケージを使う

$ npm install mysql2

接続

var express = require('express');
const mysql = require('mysql2');

const app = express();

const db_setting = {
	host: 'localhost',
	user: 'root',
	password: 'hoge',
	database: 'test'
}
let mycon = null;

(async() => {
	try {
		mycon = await mysql.createConnection(db_setting);
		mycon.connect(function(err){
			if(err){
				console.log(err);
			} else {
				console.log("success");
			}
		});
	} catch(e){
		console.log(e);
	}
	if(mycon){
		mycon.end();
	}
})();

app.listen(8000);

うーむ、asyncの外で使いたいんだよなあ