-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 816 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
const express = require('express')
const { graphqlHTTP } = require('express-graphql')
const mongoose = require('mongoose')
const cors = require('cors')
require('dotenv').config()
const Schema = require('./graphql/schema')
const Resolver = require('./graphql/resolver')
const app = express()
// body-praser
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cors())
// init graphQl
app.use('/gql', graphqlHTTP({
schema: Schema,
rootValue: Resolver,
graphiql: true
}))
// make connection to DB
mongoose.connect(process.env.URI, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(console.log('database is connected'))
.catch(err => console.log(err))
const port = process.env.PORT || 2
app.listen(port, console.log(`server runing on port:${port}`))