-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (25 loc) · 833 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
const express = require('express')
const graphqlHTTP = require('express-graphql')
const schema = require('./schema/schema')
const mongoose = require('mongoose')
require('dotenv').config()
const cors = require('cors')
const app = express()
//Allow cros-origin request
app.use(cors())
const connectionString = `mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_CLUSTER}/${process.env.DB_NAME}?retryWrites=true&w=majority`;
mongoose.connect(connectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(res => console.log("Connected to DB"))
.catch(err => console.log(err))
app.use(
'/graphql',
graphqlHTTP({
schema: schema,
graphiql: true
}),
)
app.listen(4000, () => {
console.log('Listening for request on port number 4000!')
})