choi

board first

var mysql = require('mysql');
var config = require('./db_info').board;
module.exports=function(){
return{
init: function(){
return mysql.createConnection({
host:'localhost',
port:'3306',
user:'root',
password:'2016104101',
database:'board'
// host:config.host,
// port:config.port,
// user:config.user,
// password:config.password,
// database:config.database
})
}
}
}
\ No newline at end of file
module.exports=(function(){
return{
board:{
host:'localhost',
port:'3306',
user:'root',
password:'2016104101',
database:'board'
},
example: {
host: '',
port: '',
user: '',
password: '',
database: ''
},
}
})
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>묵호 - 놀이터</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="../assets/favicon.ico" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" type="text/css" />
<!-- Google fonts-->
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="../css/styles.css" rel="stylesheet" />
</head>
<body>
</body>
</html>
\ No newline at end of file
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var path = require('path') // 상대경로
var mysql_odbc = require('../../db/db_board')();
var board = mysql_odbc.init();
router.get('/:page', function(req, res, next) {
var page = req.params.page;
var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " +
"date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from board";
board.query(sql, function(err,rows) {
if (err) console.error("err : " + err);
res.render('list.ejs', {title: '게시판 리스트', rows: rows})
})
});
router.get('/', function(req,res,next){
res.redirect('/board/1')
})
module.exports = router;
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css'/>
</head>
<body>
<h1><%= title %></h1>
<a href="/board/write">글쓰기</a>
<table border="1">
<tr>
<td>번호</td>
<td>작성자</td>
<td>제목</td>
<td>조회수</td>
<td>수정일</td>
<td>등록일</td>
</tr>
<%
for(var i=0; i<rows.length; i++)
{
var data = rows[i];
%>
<tr>
<td><%=data.idx%></td>
<td><%=data.name%></td>
<td><a href="/board/read/<%=data.idx%>"><%=data.title%></a></td>
<td><%=data.hit%></td>
<td><%=data.modidate%></td>
<td><%=data.regdate%></td>
</tr>
<%}%>
</table>
</body>
</html>