-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (29 loc) · 892 Bytes
/
index.js
File metadata and controls
37 lines (29 loc) · 892 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
const dotenv = require('dotenv');
dotenv.config();
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const appRoute = require('./route/app');
const userRoute = require('./route/user');
mongoose.set('strictQuery', false);
const dbString = process.env.DATABASE_URL;
const port = process.env.PORT;
mongoose.connect(dbString);
const db = mongoose.connection;
db.on('error', (error) => {
console.log(error);
});
db.on('connected', () => {
console.log('database is connected');
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/api', appRoute);
app.use('/api', userRoute);
app.use('', (req, res) => {
res.json('page is not found');
});
app.listen(port, () => {
console.log(`server is running on ${port}`);
});