-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (24 loc) · 882 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
import express from 'express'
import expressGraphQL from 'express-graphql';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import cors from 'cors';
import schema from "./graphql";
require('dotenv').config({ path: './config/.env'})
const app = express();
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 4000;
const db = process.env.DB; // set your database url in the environment variable or add it here
mongoose.connect( db, { useCreateIndex: true, useNewUrlParser: true })
.then(() => console.log("MongoDB Connected"))
.catch( err => console.log(err));
app.use(
"/graphql",
cors(),
bodyParser.json(),
expressGraphQL({ schema, graphiql: true })
);
app.listen( PORT, () => {
console.log(`🚀 Server ready at http://${HOST}:${PORT}`)
console.log(`🚀 Graphql ready at http://${HOST}:${PORT}/graphql`)
})