-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (30 loc) · 714 Bytes
/
index.js
File metadata and controls
38 lines (30 loc) · 714 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
37
38
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";
const app = express();
const PORT = process.env.PORT || "4000";
const { mLab: db } = process.env;
// Connect to MongoDB with Mongoose.
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 running on port ${PORT}`));