app.js
887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
//var session = require('express-session');
var mongoose = require('mongoose');
//DB연결
mongoose.connect('mongodb://username:pwd@1.201.139.92/dbname');
var db = mongoose.connection;
//연결실패
db.on('error', function()
{
console.log('Connection Failed!');
});
//연결 성공
db.once('open', function()
{
console.log('Connected!');
});
// DB모델정의
var Users = require('./models/users');
// ejs사용
// json사용설정
app.set('view engine','ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// router import
var router = require('./routing')(app, Users);
var server = app.listen(23023, function()
{
var host = server.address().address;
var port = server.address().port;
console.log("http://%s:%s",host, port);
});