-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
23 lines (19 loc) · 821 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
const express = require("express");
const { graphqlHTTP } = require("express-graphql"); //the name is a convention
const mongoose = require("mongoose");
const schema = require("./schema/schema");
const app = express();
// connect to atlas db
mongoose.connect(
"mongodb+srv://solomonndi96:solagbaby96@cluster0.qtper.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
{ useNewUrlParser: true, useUnifiedTopology: true }
);
const con = mongoose.connection;
con.once("open", () => console.log("connected to db"));
con.on("error", (err) => console.error(err));
/**
* go to graphql route. express sees this and knows that this is something that should
* go to express-graphql
*/
app.use("/graphql", graphqlHTTP({ schema, graphiql: true }));
app.listen(4000, () => console.log("app listening on port 4000"));