const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const homeRouter = require('./routers/homeRouter')
const port = process.env.port||8080;

const app = express();

// Connect Database
mongoose.connect('mongodb://localhost:27017/studentdata', {useNewUrlParser:true});
const db = mongoose.connection;
db.on("error", ()=>{console.log("error");})
db.once("open", ()=>{console.log("connected");})


app.set('view engine', 'ejs');

app.use(express.static('public'));

app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

app.use('/', homeRouter)

app.listen(port, () => {
    console.log("Listen on the port 8080");
});