Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created January 9, 2020 09:27
Show Gist options
  • Select an option

  • Save dalcon10028/ef958d0ce42f8d248a6fa9d30893dfe2 to your computer and use it in GitHub Desktop.

Select an option

Save dalcon10028/ef958d0ce42f8d248a6fa9d30893dfe2 to your computer and use it in GitHub Desktop.
MySQL with Node.js
const mysql = require('mysql');
const express = require('express');
var app = express();
const bodyparser = require('body-parser');
app.use(bodyparser.json());
var mysqlConnection = mysql.createConnection({
host : '13.124.119.246',
user : 'root',
password : 'root',
database : 'USER',
port : '56891'
});
mysqlConnection.connect((err)=>{
if (!err) {
console.log("연결됨");
}else{
console.log("연결 실패");
}
});
app.listen(3000, ()=>console.log('express서버가 3000번 포트로 열렸어요!'));
app.get('/user', (res, req)=> {
mysqlConnection.query('SELECT * FROM USER', (err, rows, fields)=>{
if(!err){
console.log(rows);
}else{
console.log(err);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment