-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (32 loc) · 1016 Bytes
/
app.js
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
42
43
44
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const fileUpload = require('express-fileupload');
const http = require('http');
const mongoose = require('mongoose');
const router = require('./router.js');
require('dotenv').config({path:'./app.env'});
const app = express();
app.use(fileUpload({}));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
const port = process.env.PORT || 4000
app.set('port', port);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(router)
const server = http.createServer(app);
const start = async () => {
try {
await mongoose.set('strictQuery', true);
await mongoose.connect(process.env.MONGO_URI)
server.listen(port);
console.log(`Server ${port} da ishga tushdi`)
} catch (e) {
console.error('error', e)
}
}
start();