Created
January 9, 2020 09:27
-
-
Save dalcon10028/ef958d0ce42f8d248a6fa9d30893dfe2 to your computer and use it in GitHub Desktop.
MySQL with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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