-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
44 lines (35 loc) · 1013 Bytes
/
index.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 _ = require('lodash');
const mongoose = require('mongoose');
const express = require('express');
const bodyParser = require('body-parser');
const { graphqlHTTP } = require('express-graphql');
const cors = require('cors');
const schema = require('./Schema/Schema');
const { URI } = require('./keys/dev')
const app = express();
app.use(cors());
app.use( bodyParser.json());
// having options to connect to the db
options = {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify:false
}
// connecting to the db
mongoose.connect(URI, options);
// adding event listeners
mongoose.connection.once('connected', ()=>{
console.log("Connected to the Database!");
}).on('error', ()=>{
console.log("Error connecting to the Database!");
});
// graphql route
app.use('/graphql',graphqlHTTP({
schema,
graphiql: true
}));
// listening on port
PORT = process.env.PORT || 1000;
const server = app.listen(PORT, ()=>{
console.log("Listening to requests on port", PORT);
});