-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 852 Bytes
/
index.js
File metadata and controls
36 lines (28 loc) · 852 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
const express = require('express');
const routes = require('./routes/api')
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
require('dotenv').config();
// Setting up express app
const app = express();
// connect to mongdb
connectDatabase();
async function connectDatabase(){
await mongoose.connect(process.env.dbURI)
.then
console.log("Connected to database successfully")
};
mongoose.Promise = global.Promise;
app.use(express.json());
// app.use(express.urlencoded({extended: true}));
// route handler
app.use('/api', routes);
// error handling middleware
app.use(function(err, req, res, next){
console.log(err);
res.status(422).send({error: err.message});
});
// listen for requests
app.listen(process.env.port || 4000, function(){
console.log('listening for requests on port 4000')
});